I am trying to call a smart constract function with the following abi with pragma experimental ABIEncoderV2:

        "constant": false,
        "inputs": [
                "name": "blockNumber",
                "type": "uint256"
                "name": "data",
                "type": "bytes"
                "name": "tokenNum",
                "type": "uint256"
        "name": "execute",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"

The data parameter is a struct with the following definition in solidity

struct InputParams {
        address addressFirst;
        address addressSecond;
        uint256 tokenAmount;

How can I encode the data on the python side? I am getting error

Could not identify the intended function with name `execute`, positional argument(s) of type `(<class 'int'>, <class 'list'>, <class 'int'>)` and keyword argument(s) of type `{}`. Found 1 function(s) with the name `execute`: ['execute(uint256,bytes,uint256)']

I think I need to convert the python list into 'bytes' type, but how do I specify in the bytes that necessary datatypes of the struct?


For anyone looking for this, the proper way to do it is with encode_abi from python package eth_abi

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.