metaMask
2019-12-31 本文已影响0人
宋song一
一 、根据交易hash查询交易详情
pollForCompletion: function (txHash) {
let calledBack = false
// Normal ethereum blocks are approximately every 15 seconds.
// Here we'll poll every 2 seconds.
const checkInterval = setInterval(function () {
const notYet = 'response has no error or result'
ethereum.send('eth_getTransactionByHash', [txHash])
.then(function (response) {
const transaction = response.result
clearInterval(checkInterval)
calledBack = true
// callback(null, transaction)
console.log(transaction)
})
.catch(function (err, response) {
if (calledBack) return
if (err || response.error) {
if (err.message.includes(notYet)) {
return 'transaction is not yet mined'
}
// callback(err || response.error)
console.log(err || response.error)
}
})
}, 2000)
}