Search code examples
blockchainrpcrsk

How can I find out the number of times an RSK transaction has been confirmed on the RSK blockchain?


It would be good to know how many times a transaction has been confirmed on the RSK blockchain so that when one user sends RIF to another wallet or to an exchange wallet for example we can see how many confirmations have occurred


Solution

  • You can also do it with web3.js. As function

    const getTxConfirmations = (txHash) => Promise.all([
        web3.eth.getTransaction(txHash).then(tx => tx.blockNumber),
        web3.eth.getBlockNumber()
    ]).then(([blockNumber, currentBlockNumber]) => (currentBlockNumber - blockNumber))
    

    And with Truffle console:

    truffle(develop)> web3.eth.getTransaction('0x7a28a121c41085ef52d449f64120dbc422ec70b4d324c076c8d89222cf7188c8').then(tx => tx.blockNumber)
    1
    truffle(develop)> web3.eth.getBlockNumber()
    5
    truffle(develop)> const getTxConfirmations = (txHash) => Promise.all([web3.eth.getTransaction(txHash).then(tx => tx.blockNumber), web3.eth.getBlockNumber()]).then(([blockNumber, currentBlockNumber]) => (currentBlockNumber - blockNumber))
    undefined
    truffle(develop)> getTxConfirmations('0x7a28a121c41085ef52d449f64120dbc422ec70b4d324c076c8d89222cf7188c8')
    4