reactjs - 如何将参数发送到 ContractForm 中的方法
问题描述
我有一个 React 组件
<ContractForm contract="SomeContract" method="setEmployee" />
我的soliditysetEmployee
方法看起来像这样
function setEmployee(
address employeeAddress,
uint _statusType
) public onlyOwner {
...
}
如何setEmployee
从我的 React 前端向该方法发送地址和字符串?我究竟在哪里将参数传递给合同中的方法?
解决方案
您需要将实际函数传递给 ContractForm,您目前只是传递一个字符串。
<ContractForm contract="SomeContract" method={setEmployee} />
然后在 ContractForm 组件中,您可以通过方法 prop 调用该函数:
this.props.method(employeeAddress, _statusType);
编辑 我的理解是 setEmployee 在父组件中。我不熟悉在 React 中使用 Truffle/.sol 文件。
推荐阅读
- ios - 无法将“Swift.__SwiftDeferredNSArray”(0x104cd8ae8)类型的值转换为“NSMutableArray”(0x7fff87c52960)
- javascript - 为什么 axios 在解析推特搜索 api 响应后会以某种方式修改推文的 id?
- asp.net - 我可以像 Tinymce 一样将 Gutenberg 文本编辑器与 Asp.net 明确集成吗?
- javascript - 在图片网址中添加字符串
- pdf - 谁使用 PDF 中的 `UserUnit` 属性?
- lua - 如何使用停止按钮停止音乐播放?
- python - 如何在 Django 中为 zip 文件创建可下载的 URL?
- android - 我无法通过 taskSnapshot.getStorage().getDownloadUrl().toString() 方法加载我的图像,请告诉我是否有任何建议
- splunk-query - 我可以使用什么正则表达式命令在 splunk 中创建一个字段
- axios - 使用 axios GET 请求到端口 81(甚至是 js 本机 fetch)