cryptocurrencybinancebinance-smart-chainbinance-chain

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. 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? Will they work with BEP20?


Solution

  • 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.

    If you use correct version of Solidity compiler, it should tell if the code needs further changes. For real life testing, it's better to test the code on testnet of Binance Smart Chain.