0

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?

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

1 Answer 1

0

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

3
  • 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
    Commented Nov 6, 2019 at 8:59
  • Here I think github.com/ethereum/web3.js/blob/2.x/packages/web3-eth-abi/src/…
    – Kivutar
    Commented Nov 6, 2019 at 12:05
  • 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
    Commented Nov 15, 2019 at 0:47

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.