For example, a function's name and parameters are given as following:

function batchTransfer(address[] _receivers, uint256 _value) public returns (bool);

Then I want to get a python dictionary whose key is the first location of the value in transaction input, and value is the corresponding value, for example:

p {};

p["0"] = 0x34672534; // the function signature

p["4"] = 'offset'; // the offset of '_receivers' value

p["36"] = '_value';

p["4+offset"] = '_receivers.length'; // the length of '_receivers'

p["4+offset+1*32"] = '_receivers[1]'

p["4+offset+2*32"] = '_receivers[2]'

Note: since when reaching this stage, only contract source codes and ABI were given, and there are no concrete inputs, namely, I should derive this dictionary by statically analyzing source codes or ABI, so the location can be expressed by expressions as shown above.

So, is there any way to implement such a parser to get this map?

Or is there already an existing one?

  • A mapping(string -> string) doesn't seem appropriate here. To begin with, neither 0x34672534 nor _value is of type string. Please refine your question. – goodvibration Nov 5 at 7:00
  • Sorry, I rewrote my question. – Jocelyn Nov 5 at 11:20

One way is to use this https://github.com/ConsenSys/abi-decoder or even better https://web3js.readthedocs.io/en/v1.2.0/web3-eth-abi.html#decodeparameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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