[英]How to receive ETH in a smart contract
我正在做一个 ico,我得到了这个代码,众筹是用 dai 代币,但我想用 ether,我该怎么做?
IERC20 public dai = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
function buy(uint etherAmount)
external
icoActive() {
require(
etherAmount >= minPurchase && etherAmount <= maxPurchase,
'have to buy between minPurchase and maxPurchase'
);
uint tokenAmount = etherAmount.div(price);
require(
tokenAmount <= availableTokens,
'Not enough tokens left for sale'
);
dai.transferFrom(msg.sender, address(this), etherAmount);
token.mint(address(this), tokenAmount);
sales[msg.sender] = Sale(
msg.sender,
tokenAmount,
false
);
}
您可以使用payable
的 function 修饰符。 请参阅文档如何在智能合约中接收以太币。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.