metaMask

作者: 宋song一 | 来源:发表于2019-12-31 15:29 被阅读0次

一 、根据交易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)
}

相关文章

网友评论

      本文标题:metaMask

      本文链接:https://www.haomeiwen.com/subject/vnnboctx.html