首页 > 解决方案 > 如何将参数发送到 ContractForm 中的方法

问题描述

我有一个 React 组件

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

我的soliditysetEmployee方法看起来像这样

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

如何setEmployee从我的 React 前端向该方法发送地址和字符串?我究竟在哪里将参数传递给合同中的方法?

标签: reactjstruffle

解决方案


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

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

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

this.props.method(employeeAddress, _statusType);

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


推荐阅读