简体   繁体   中英

Crowdsale for already minted token (BEP20)

I currently have a BEP20 token which is owned by over 50 people (and hence why I dont want to mint another token). I'm looking to crowdsale it to more but I don't seem to find any tutorials of how to make a crowdsale contract for an already minted token.

Can anyone show me the way? I'm a beginner at solidiy and openzepplin but I am willing to learn. Thanks

Here's a simple crowdsale contract. It needs to hold the tokens (you need to send them to this contract address) before users are able to buy them.

pragma solidity ^0.8;

interface IERC20 {
    function transfer(address to, uint256 amount) external returns (bool);
}

contract Crowdsale {
    IERC20 public token;
    uint256 price; // amount of tokens per 1 ETH

    constructor (address _token, uint256 _price) {
        token = IERC20(_token);
        price = _price;
    }

    function buy() external payable {
        uint256 amount = price * msg.value;
        token.transfer(msg.sender, amount);
    }
}

You can add more features such as:

  • max order per address
  • manually or dynamically adjusted pricing
  • being able to withdraw the tokens back from the contract to a predefined address
  • validation if the crowdsale contract has sufficient token balance (so that it fails with a custom error message in case of insuficient balance)
  • etc...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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