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. Nov 5 '19 at 7:00
  • Sorry, I rewrote my question.
    – Jocelyn
    Nov 5 '19 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

  • I searched the source codes of 'decodeparameters' function in Web3. but i found it was imported from another unknown package, could you please tell me where i can find the codes of 'decodeparameters'.
    – Jocelyn
    Nov 6 '19 at 8:59
  • This page also uses a packed function 'decodeParameter()' imported from another package. Finally, I found this package was 'ethers' (docs.ethers.io/ethers.js/html/getting-started.html) but it's impemented by JS. I wander if there is any straight way to implement my expected function without refering abicoders
    – Jocelyn
    Nov 15 '19 at 0:47

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.