以太坊DApp开发与智能合约基础
1. 发送交易
首先,我们编写一个函数来发送交易,以调用 Counter 合约的 increase 函数:
increaseCounter() {
const counter = this.props.contract;
return counter.methods.increase().send();
}
这里使用 send() 方法而非 call() 方法,因为我们需要实际发送交易来影响合约状态,而不只是从网络查询数据。
接下来,我们将这个方法绑定到界面的按钮上,并进行测试。以下是更新后的 render 方法:
render() {
const { value } = this.state;
if (!value) return "Loading";
return (
<div>
<div>Counter value: { value.toString() }</div>
<button onClick={() => this.increaseCounter()}>
Increase counter
</button>
</div>
超级会员免费看
订阅专栏 解锁全文
1187

被折叠的 条评论
为什么被折叠?



