4

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?

1 Answer 1

2

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

1
  • Can you share some sample code, or a URL ? Thanks.
    – jdbertron
    Dec 24, 2022 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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