Every Ethereum transaction that represents a function call on a smart contract holds an input field with data that corresponds to the data sent through the interface of the function. For example, this transaction (
https://etherscan.io/tx/0x3a7d091970d7931dd5ef4872e59093234e132f861139403d2b69db80ac2d0ecb) is a newProposal function on The DAO. You can that etherscan separates the data into 32 byte chunks. It's relatively easy to pick off the first 'address' and the second 'debatingPeriod,' but I'm having trouble from there. I'm assuming that the next 32 byte second is the start of the string description, and I am further assuming that it is in RLP format as described here: https://github.com/ethereum/wiki/wiki/RLP, but I'm not so sure.
According the RLP document, a third 32 byte section should be only a single byte long and if it represents 0xca it means an empty list (see examples at the bottom).
So two questions: (1) how does one parse the input data (particularly strings) of the data provided by ehterscan.io, and (2) does etherscan represent the data as it actually exists on the blockchain?
Function: newProposal(address _recipient, uint256 _amount, string _description, bytes _transactionData, uint256 _debatingPeriod, bool _newCurator)
Best Answer
Q1 how does one parse the input data (particularly strings) of the data provided by etherscan.io
You will find the information to encode the arguments at Ethereum Contract ABI.
To decode the parameters, see Encoding/Decoding contract ABI data.
And here is a JavaScript version of ethabi - https://github.com/jacogr/ethabi-js.
Here's an example using
ethabi
. I've created a shell scriptdecodeIt
with the following contents:And here is the output when I run
decodeIt
:And here is the code from github.com/ethcore/ethabi/.../decoder.rs, lines 43 to 214:
Q2 does etherscan represent the data as it actually exists on the blockchain?
Yes.
For transaction 0x3a7d091970d7931dd5ef4872e59093234e132f861139403d2b69db80ac2d0ecb, the data from etherscan.io follows:
In
geth
we can retrieve the same data (I've formatted theinput:
data):You can find some further transactional information using
eth.getTransactionReceipt(txHash)
:And if you want the intermediate execution details of the transaction, use
debug.traceTransaction(txHash)
. Note that this data is not available in--fast
synced blockchain data: