New Answer (Based on comment)
To get the value of ERC20 tokens being transferred, you need to parse the input data of the transaction.
Per the standard, the transfer
function looks as follows:
function transfer(address _to, uint256 _value) public returns (bool success)
This means that you must look for the final parameter in the input data. An example transaction can be seen here. In this example, the input data is as follows:
0xa9059cbb000000000000000000000000dfbc84ccac430f2c0455c437adf417095d7ad68e0000000000000000000000000000000000000000000000158b5ff8fb42b95000
0xa9059cbb
This is the hash of the method signature.
000000000000000000000000dfbc84ccac430f2c0455c437adf417095d7ad68e
This is the address where the tokens are being sent.
0000000000000000000000000000000000000000000000158b5ff8fb42b95000
This is the amount (in Hex) and is the value you are looking for. In this example, this comes out to 397.424645 tokens.
Original Answer
The value
of the transaction is actually not in the input
data, but rather in its own value
field. If you know the hash, you can get the value.
>>> tx_data = web3.eth.getTransactionReceipt(tx_hash)
>>> print(tx_data["value"])
1000000000000000000
If you get the transaction receipt, the value
field will be included in the output. That is the amount of Wei sent in the transaction.
the value of the transaction
?balanceOf
your account (or thetotalSupply
of the contract) before and after the transaction, and figure it out.Transfer
event in the logs of the transaction receipt (which you can obtain using the transaction hash).w.eth.getTransactionReceipt('0xe95730480647c4298ec0e2376f619f7425d9e4cf4b1c7ba0415b1a8a81b54a21')
and if I take the value in the data, and doint('0x0000000000000000000000000000000000000000000000000000000000000050',0)
I see that I get the correct value. Is this approach correct ?