useDAppuseDApp
  • 开始
  • 指南
  • 代币
⌘ K
安装
读取
写入
Create Eth App
最后更新时间:
帮助改进此文档
Made with ❤️ by 紫升

写入

如果要将一个改变状态的交易写入区块链,可以使用 useSendTransaction 钩子。

在组件中简单地调用一个 Hook 函数。

const { sendTransaction } = useSendTransaction()

通常你会在点击按钮的处理函数中使用 sendTransaction。

const handleClick = () => {
setDisabled(true)
sendTransaction({ to: address, value: utils.parseEther(amount) })
}

See the Ether Transactions guide for a more in-depth explanation, or take a look at Contract Functions if you are interested in writing transactions to contracts.