5

Can I get the confirmations of a transaction using Solidity? If not, is there any other method I can use to get confirmations programmatically?

I hope when user submits one transaction, the web can show the result and the result won't be changed later. The users accept to wait the longer time, example 1 or 3 minutes, for making sure the transaction is finished.

eth
  • 85,679
  • 53
  • 285
  • 406
黃智祥
  • 465
  • 6
  • 16

2 Answers2

3

Solidity and the web are different. Solidity itself does not have access to past transactions. For the web, you would use web3.js and see the code at How can a DApp detect a fork or chain reorganization using web3.js or additional libraries? which waits specified number of blocks and verifies the transaction receipt is still valid. In this method, the user doesn't have to wait 1 or 3 minutes (after they click a button to submit a transaction), and if there is a chain reorg, the UI can be updated: the UI could let the user know that they have to resubmit their transaction.

eth
  • 85,679
  • 53
  • 285
  • 406
3

This was mentioned in another question, also here

Number of confirmations is the current block number minus the transaction's block number (if any).

For web3, this can be found by the following command

web3.eth.blockNumber - web3.eth.getTransaction(<txhash>).blockNumber

I think the same would also work in Geth console after removing the web3.'s.

jeff
  • 2,550
  • 2
  • 18
  • 40