How to pass tuples and structs using web3.py or blockchain explorers

400 views Asked by At

How should I pass the following arguments to sendOFT function in This smart smart contract using python web3.py and block explorer? Here are the data types:

sendOFT arguments

FeeObj

I get an error when I pass elements like this. Here is a sample transaction and this is it's decoded input data:

sample tx

I would appreciate a complete input sample for both python web3.py(web3.js would be good as well) and Block Explorer.

1

There are 1 answers

2
Mikko Ohtamaa On

In web3.py, you can pass a Solidity struct as

For example:


contract TupleContract {
    struct T { int x; bool[2] y; address[] z; }
    struct S { uint a; uint[] b; T[] c; }

    function method(S memory s) public pure returns (S memory) {
        return s;
    }
}

If you pass struct as a tuple, arguments must be in the same order as they are in Solidity source code.

You would encode this for a smart contract call as following


my_struct_t = (1, [False, False], ["0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000"])

my_struct_s = (1, [1, 1], [my_struct_t, my_struct_t])

tuple_contract.functions.method(my_struct_s).transact({...})

See Web3.py documentation for more information.

As block explorers tend to be proprietary software, you need to contact the support desk of any block explorer to learn how to use their software, and this job should not be outsourced to the public community.