10

Using web3, how can you get the Tx cost and data/payload for a given transaction?

getTransaction(tx#) returns everything but those 2 values. This information seems to be available via blockchain explorers such as etherchain.org

q9f
  • 32,913
  • 47
  • 156
  • 395
dbryson
  • 6,403
  • 2
  • 27
  • 37

1 Answers1

12

web3.eth.getTransaction has an input property, which is the /payload for a given transaction.

The cost of a transaction is gasUsed multiplied by gasPrice.
web3.eth.getTransactionReceipt has the gasUsed property. web3.eth.getTransaction has gasPrice. Since the unit for gasPrice is wei, divide by 1e18 to get the Ether cost of a transaction.

eth
  • 85,679
  • 53
  • 285
  • 406