node.js - 我如何将 eth 值发送到在 ethers.js 中支付的特定智能合约功能?
问题描述
我试图在只接受一个参数的智能合约上调用应付函数。
我如何将 eth 值与函数调用一起发送到 ethers.js 中的这个函数?文档似乎没有提供太多关于最佳方式的示例。
我的函数调用
const reciept = await contract.buyPunk(1001);
所有其他读写函数调用都按预期工作,但它调用了我尚未解决的应付函数。
解决方案
const options = {value: ethers.utils.parseEther("1.0")}
const reciept = await contract.buyPunk(1001, options);
通过 ethers.js 调用合约函数时,您可以在参数末尾传递一个选项对象。该对象可以设置value
与交易一起发送的。
此处的文档:https ://docs.ethers.io/v5/api/contract/contract/#Contract-functionsCall
推荐阅读
- python - Python正则表达式字符串替换问题
- java - 如何在java中声明和加入可完成的未来响应列表
- ios - 如何在不提示非香港用户提供权限的情况下使用带有后台交付的 Healthkit 观察者查询?
- clojure - “Quick Clojure”一书的勘误表?
- image - 我们如何在 PDF 文档中添加图像字段?
- apache-spark - Spark正在将一些行加载到一列中?
- python - Python中未定义“变量”
- typescript - TypeError:无法解构“对象(...)(...)”的属性“toDos”,因为它未定义
- html - 尝试在 HTML 中创建一个适合并嵌入来自多个其他页面的结果的页面
- git - 从詹金斯管道语法增加git超时