1

I am Aditya and I want to know How to get the details of transactions through Web3.

See This TX Hash Of BscScan: https://bscscan.com/tx/0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312 Quite Beauftifull Right?

enter image description here

But In My Case Using This Code Give Result Like Crazy

tx_id = '0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312'
result = web3.eth.getTransactionReceipt(tx_id)

print(web3.toJSON(result))

Output

{"transactionIndex": 251, "blockNumber": 13614675, "gasUsed": 130167, "to": "0x10ED43C718714eb63d5aA57B78B54704E256024E", "from": "0xdde85FF49AB49615A9864a5e2aFB04b3bd2F9199", "logs": [{"address": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", "data": "0x00000000000000000000000000000000000000000000000001e01c2029dc614d", "transactionHash": 
"0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312", "blockHash": "0x60048fc2c731929fd8fffccac3707922e0e0b74cf64b503efbba759b6827600a", "topics": ["0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c", "0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e"], "blockNumber": 13614675, "transactionIndex": 251, "logIndex": 782, "removed": false}, {"address": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e", "0x00000000000000000000000058f876857a02d6762e0101bb5c46a8c1ed44dc16"], "blockNumber": 13614675, "transactionHash": "0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312", "blockHash": "0x60048fc2c731929fd8fffccac3707922e0e0b74cf64b503efbba759b6827600a", "data": "0x00000000000000000000000000000000000000000000000001e01c2029dc614d", "transactionIndex": 251, "logIndex": 783, "removed": false}, {"logIndex": 
784, "transactionHash": "0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312", "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x00000000000000000000000058f876857a02d6762e0101bb5c46a8c1ed44dc16", "0x000000000000000000000000dde85ff49ab49615a9864a5e2afb04b3bd2f9199"], "data": "0x000000000000000000000000000000000000000000000003e733628714200000", "blockNumber": 13614675, "transactionIndex": 251, "blockHash": "0x60048fc2c731929fd8fffccac3707922e0e0b74cf64b503efbba759b6827600a", "removed": false, "address": "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56"}, {"blockNumber": 13614675, "transactionHash": "0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312", "removed": false, "topics": ["0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"], "data": "0x000000000000000000000000000000000000000000005e227acf35ec4d5086e4000000000000000000000000000000000000000000c4673dd7c66fd693a21f0d", "transactionIndex": 251, "blockHash": "0x60048fc2c731929fd8fffccac3707922e0e0b74cf64b503efbba759b6827600a", "logIndex": 785, "address": "0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16"}, {"transactionIndex": 251, "logIndex": 786, "topics": ["0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822", "0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e", "0x000000000000000000000000dde85ff49ab49615a9864a5e2afb04b3bd2f9199"], "blockNumber": 13614675, "transactionHash": "0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312", "removed": false, "address": "0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16", "data": "0x00000000000000000000000000000000000000000000000001e01c2029dc614d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e733628714200000", "blockHash": "0x60048fc2c731929fd8fffccac3707922e0e0b74cf64b503efbba759b6827600a"}], "logsBloom": "0x00200200000000100000000080000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000008000000200000000000000000800400008000000800001000000000004000000000000000000000008000000000200010000000000000000000000000000000000000000000240001000000080000004000000800000000000000000000000000020000000000000000000000000000000000000000000002000000020000000000001000000000000000001000000000000080000000000000000000000000000001000000000000000000400000000000000000", "status": 1, "transactionHash": "0xa826ea39430a7d77f1b0ba31eb0de9f54662c8a7b891ca0bec8affce96bbb312", "blockHash": "0x60048fc2c731929fd8fffccac3707922e0e0b74cf64b503efbba759b6827600a", "contractAddress": null, "cumulativeGasUsed": 41055238, "type": "0x0"}

Well anyone knows how to get all this info? or it is encoded or something. I want to get the Value Of Transaction which is something approx 71$ in this TX.

1 Answer 1

4

Method web3.eth.getTransaction(<TX_HASH>); will return an object which will have property value and this is the value parameter passed to the transaction, but represented as wei. To convert it to ETH ( or BNB in your case ) you need to use web3.utils.fromWei(<WEI_AMOUNT>, 'ether');. Now you got the ETH ( or BNB ) amount, if you want to find the USD value of it you have to use external API like coinmarketcap or coingecko to get the USD value equivalent of the transaction value.

Example:

web3.eth.getTransaction(<TX_HASH>, function(err, result) {
    if (result.value) {
        console.log(web3.utils.fromWei(result.value, 'ether'));
    }
});
1
  • thanks buddy you really helped me
    – Aditya Dev
    Commented Dec 21, 2021 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.