如何使用 web3.py 或区块链浏览器传递元组和结构

问题描述 投票:0回答:1

如何使用 python web3.py 和区块浏览器将以下参数传递给

This
智能合约中的 sendOFT 函数? 以下是数据类型: sendOFT arguments FeeObj 当我传递这样的元素时,我收到错误。 这是一个 sample 交易,这是它的解码输入数据: sample tx

我希望有 python web3.py(web3.js 也很好)和块资源管理器的完整输入示例。

ethereum solidity web3js web3py etherscan
1个回答
0
投票

在 web3.py 中,您可以将 Solidity

struct
传递为

例如:


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;
    }
}

如果将结构体作为元组传递,则参数的顺序必须与 Solidity 源代码中的顺序相同。

您可以将其编码为智能合约调用,如下所示


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({...})

请参阅 Web3.py 文档以获取更多信息

由于区块浏览器往往是专有软件,您需要联系任何区块浏览器的支持台以了解如何使用他们的软件,并且这项工作不应外包给公共社区。

© www.soinside.com 2019 - 2024. All rights reserved.