Crowdsale contract

From OpenZeppelin’s docs, I could get this script for minted crowdsales.

\

contract MyToken is ERC20, ERC20Mintable {
    // ... see "Tokens" for more info
}

contract MyCrowdsale is Crowdsale, MintedCrowdsale {
    constructor(
        uint256 rate,    // rate in TKNbits
        address payable wallet,
        IERC20 token
    )
        MintedCrowdsale()
        Crowdsale(rate, wallet, token)
        public
    {

    }
}

contract MyCrowdsaleDeployer {
    constructor()
        public
    {
        // create a mintable token
        ERC20Mintable token = new MyToken();

        // create the crowdsale and tell it about the token
        Crowdsale crowdsale = new MyCrowdsale(
            1,               // rate, still in TKNbits
            msg.sender,      // send Ether to the deployer
            token            // the token
        );
        // transfer the minter role from this contract (the default)
        // to the crowdsale, so it can mint tokens
        token.addMinter(address(crowdsale));
        token.renounceMinter();
    }
}

I have several questions:
1-What code should be put in // … see “Tokens” for more info
2- How to deploy it on the blockchain for a bsc token using remix.ethereum.org?

I think this depends on you, you can add some functions you want to achieve, such as you can add a function mint() to allow to mint new tokens after deploying. If you do not add anything, it is just a common ERC20 token, and you can have a look at this documentation to check which functions does it have. ERC 20 | OpenZeppelin Docs

Emmmm, there is a tutorial that does not satisfy your original target, but I think it can help
Create an ERC20 using Remix, without writing Solidity | OpenZeppelin Community

Thanks a lot for your fast reply :clap:
I have a basic knowledge of how to deploy smart contracts but on the crowdsale contract, I dont know how to grant it the permission to mint new tokens on the token contract. This is my question more precisely.

And here:

Crowdsale crowdsale = new MyCrowdsale(
            1,               // rate, still in TKNbits
            msg.sender,      // send Ether to the deployer
            token            // the token
        );

I just need to provide the Token name or the token contract address?
Otherwise how can it know what token it should interact with?

Yeah, you are right, I think it should be the token contract address.

Hello Skyge,
Sorry for the late reply so If I understand well, it should be like this:
Presale.sol file content

new Crowdsale(
    1,             // rate in TKNbits
    MY_WALLET,     // address where Ether is sent
    TOKEN_ADDRESS  // the token contract address
);
contract MyToken is ERC20, ERC20Mintable {
    mint();
}

contract Presale is Crowdsale, MintedCrowdsale {
    constructor(
        uint256 rate,    // rate in TKNbits
        address payable wallet,
        IERC20 token
    )
        MintedCrowdsale()
        Crowdsale(rate, wallet, token)
        public
    {

    }
}

contract PresaleDeployer {
    constructor()
        public
    {
        // create a mintable token
        ERC20Mintable token = new MyToken();

        // create the crowdsale and tell it about the token
        Crowdsale crowdsale = new MyCrowdsale(
            1,               // rate, still in TKNbits
            msg.sender,      // send Ether to the deployer
            token            // the token
        );
        // transfer the minter role from this contract (the default)
        // to the crowdsale, so it can mint tokens
        token.addMinter(address(crowdsale));
        token.renounceMinter();
    }
}

Then after the crowdsale is created, don’t forget to approve it to use your tokens!

IERC20(tokenAddress).approve(CROWDSALE_ADDRESS, SOME_TOKEN_AMOUNT);

where can I use this type of command:

IERC20(tokenAddress).approve(CROWDSALE_ADDRESS, SOME_TOKEN_AMOUNT);
1 Like