简体   繁体   English

如何在Web3 v1中使用带有ERC20令牌的应付款功能

[英]How to use a payable function with a ERC20 token with web3 v1

I have a function in my Ethereum smart contract with the following interface 我的以太坊智能合约中具有以下界面的功能

// submitting a review requires a payment
function addReview(string review) public payable

Using web3 v1 invoking this function would be something like this 使用web3 v1调用此功能将类似于以下内容

contract.methods.addReview(review).send({
 from: accounts[0],
 value: SOME_AMOUNT_IN_ETH
})

How can I invoke this function with a different ERC20 token rather than using Ether? 如何使用其他ERC20令牌而不是Ether调用此函数?

If your payable function is foo and takes 1 parameter and you want to send x amount of ether and contract is the contract you want to refer to, you would invoke it like that: 如果您的应付款功能是foo并带有1个参数,并且您想发送x数量的以太币,而contract是您要引用的合同,则可以这样调用它:

contract.foo.value(x).(param1)(msg.sender);

I hope it is clear. 我希望这很清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM