如何从可靠的智能合约中向令牌持有者发送令牌?这意味着如何向代币持有者发送奖励?
发布于 2021-11-05 00:50:15
有一个地址列表,并在调用本机erc传输方法时遍历它们。在不知道访问键的情况下,您不能真正迭代映射(如果您正在考虑从smth中提取地址,如balances)。
发布于 2021-11-09 04:41:08
我假设您想要将Ether发送到另一个智能合约或EOA (例如Metamask)。您可以像下面这样编写智能合约,并使用Remix Ethereum ( IDE)将Ether发送给外部方。使用公共函数- transferEther。
//SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.6.0 < 0.9.0;
contract Sample{
address public owner;
constructor() {
owner = msg.sender;
}
receive() external payable {
}
fallback() external payable {
}
function getBalance() public view returns (uint){
return address(this).balance;
}
// this function is for sending the wei/ether OUT from this smart contract (address) to another contract/external account.
function transferEther(address payable recipient, uint amount) public returns(bool){
require(owner == msg.sender, "transfer failed because you are not the owner."); //
if (amount <= getBalance()) {
recipient.transfer(amount);
return true;
} else {
return false;
}
}
}https://stackoverflow.com/questions/69813901
复制相似问题