ethereum - 如何使用 web3j 将元组编码为函数的输入参数

标签 ethereum solidity web3-java

我正在尝试调用一个类似于以下内容的 Solidity 函数:

function fillOrder(
    Order memory order,
    uint256 takerAssetFillAmount,
    bytes memory signature
)

使用 web3j 我会创建类似于下面的函数,但是我不太确定如何表示在 Solidity 中表示为结构的顺序。

List<Type> inputParams = Arrays.asList(???, new 
Uint256(takerAssetFillAmount), new Bytes32(signture));
new Function("fillOrder", inputParams, Collections.emptyList());

关于如何表示结构的任何指示?

谢谢。

最佳答案

您可以用方括号将参数括起来。

例如,假设我有一份契约(Contract):

contract Test {
    struct Foo {
        uint a;
        string b;
        address c;
    }

    function bar (Foo memory foo) public {
        c = foo.c;
    }
}

我可以使用 web3.js 调用 bar 函数,如下所示:

contract.methods.foo([123, "123", "0xABC...."]).send({ from: '0x...' })

关于ethereum - 如何使用 web3j 将元组编码为函数的输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52620848/

相关文章:

ethereum - Solidity 中的修饰符有什么作用?

solidity - 在测试网上使用 Remix 部署合约时出现问题

java - Web3j Transfer.sendFunds() 返回错误 "insufficient funds for gas * price + value"

java - Web3j 读取单个事务的所有发出事件

java - 无法使用 web3j 下载以太坊 Activity

ethereum - 智能合约部署需要很长时间

javascript - 通过Web3访问智能合约成员功能

blockchain - Solidity 基础知识 : what "msg.sender" stands for

ethereum - 如何使用 ethers.js 创建无气体交易/元交易?

node.js - Web3.js 以太坊 - 是否可以在一笔交易中调用 2 个函数?