简体   繁体   English

具有空投功能的 BEP-20 智能合约

[英]BEP-20 smart contract with airdrop feature

I'm creating my own BEP20 token and want to implement a function to airdrop tokens to multiple addresses at once to reduce gas fees.我正在创建自己的 BEP20 代币,并希望实现 function 以一次将代币空投到多个地址以减少汽油费。 Use case would be a giveaway of free tokens to selected users after the launch.用例将是在发布后向选定用户赠送免费代币。

This is the code that I have so far, however there seems to be something missing for it to work properly:这是我到目前为止的代码,但是它似乎缺少一些东西才能正常工作:

contract Airdrop is Ownable {

IERC20 token;

struct PaymentInfo {
  address payable payee;
  uint256 amount;
}
constructor(address _token) public {
    token = IERC20(_token);
}

function batchPayout(PaymentInfo[] calldata info) external onlyOwner {
    for (uint i=0; i < info.length; i++) {
        token.transfer(info[i].payee,info[i].amount);
    }
}

function transfer(address to, uint256 amount) external onlyOwner {
    token.transfer(to, amount);
}    
}

Can I use code snippets from ERC20 examples?我可以使用 ERC20 示例中的代码片段吗? Will they work with BEP20?他们会与 BEP20 合作吗?

Ethereum and Binance Smart Chain use slightly different token standards, so most of the Solidity code designed for Ethereum virtual machine need minor changes, including replacing mentions of IERC20 with IBEP20 and using the correct Solidity file for IBEP20 interface.以太坊和币安智能链使用的代币标准略有不同,因此为以太坊虚拟机设计的大部分 Solidity 代码都需要进行细微更改,包括将提及的 IERC20 替换为 IBEP20 以及为 IBEP20 接口使用正确的 Solidity 文件。

If you use correct version of Solidity compiler, it should tell if the code needs further changes.如果您使用正确版本的 Solidity 编译器,它应该会告诉您代码是否需要进一步更改。 For real life testing, it's better to test the code on testnet of Binance Smart Chain.对于现实生活中的测试,最好在币安智能链的测试网上测试代码。

You do not need to include batch send in the token itself.您不需要在令牌本身中包含批量发送。 Because smart contracts are composable, there exist third-party smart contracts that can do batch send on behalf of any token.由于智能合约是可组合的,因此存在可以代表任何代币进行批量发送的第三方智能合约。

One example service with open-source smart contracts is Token BulkSender .使用开源智能合约的一个示例服务是Token BulkSender The source for the bulk send smart contract is here .批量发送智能合约的来源在这里

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

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