【问题标题】:How do I send parameters to the method in a ContractForm如何将参数发送到 ContractForm 中的方法
【发布时间】:2020-04-26 05:58:44
【问题描述】:

我有一个 React 组件

<ContractForm contract="SomeContract" method="setEmployee" />

我的soliditysetEmployee方法是这样的

function setEmployee(
   address employeeAddress,
   uint _statusType
) public onlyOwner {
  ...
}

如何从我的 React 前端向 setEmployee 方法发送地址和字符串?合约中的方法到底应该在哪里传递参数?

【问题讨论】:

    标签: reactjs truffle


    【解决方案1】:

    您需要将实际函数传递给 ContractForm,您目前只是传递一个字符串。

    <ContractForm contract="SomeContract" method={setEmployee} />
    

    然后在 ContractForm 组件中可以通过方法 prop 调用函数:

    this.props.method(employeeAddress, _statusType);
    

    编辑 我的理解是 setEmployee 在父组件中。我不熟悉 React 中 Truffle/.sol 文件的使用。

    【讨论】:

    • 该函数位于不同的 .sol 文件中。据我了解,React 组件只是寻找函数名
    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 2017-12-13
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 1970-01-01
    相关资源
    最近更新 更多