My Crowdsale Deployer

Hi @casper,

The example I showed was for a token that minted all it’s tokens at time of creation rather than a mintable token.

Changing to a Mintable Token and Mintable Crowdsale you can do this through the CLI:

Note: This is sample code that hasn’t been tested, any such solution would need appropriate testing and auditing.

SimpleToken

pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/Initializable.sol";

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Mintable.sol";

/**
 * @title SimpleToken
 */
contract SimpleToken is Initializable, ERC20, ERC20Detailed, ERC20Mintable {
    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    function initialize(address minter) public initializer {
        ERC20Detailed.initialize("SimpleToken", "SIM", 18);
        ERC20Mintable.initialize(minter);
    }
}

SimpleCrowdsale.sol

pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/Initializable.sol";

import "@openzeppelin/contracts-ethereum-package/contracts/crowdsale/Crowdsale.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/crowdsale/emission/MintedCrowdsale.sol";

contract SimpleCrowdsale is Initializable, MintedCrowdsale {
 
    function initialize(
        uint256 rate,    // rate in TKNbits
        address payable wallet,
        IERC20 token
    ) public initializer {
        Crowdsale.initialize(rate, wallet, token);
    }
}

Create SimpleToken

$ npx oz create
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
? Pick a contract to instantiate SimpleToken
? Pick a network development
✓ Contract SimpleToken deployed
✓ Contract SimpleCrowdsale deployed
All contracts have been deployed
? Call a function to initialize the instance after creating it? Yes
? Select which function * initialize(minter: address)
? minter (address): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
✓ Setting everything up to create contract instances
✓ Instance created at 0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B
0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B

Create SimpleCrowdsale

$ npx oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate SimpleCrowdsale
? Pick a network development
All contracts are up to date
? Call a function to initialize the instance after creating it? Yes
? Select which function initialize(rate: uint256, wallet: address, token: address)
? rate (uint256): 1
? wallet (address): 0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
? token (address): 0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B
✓ Instance created at 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550
0xC89Ce4735882C9F0f0FE26686c53074E09B0D550

Add the crowdsale as a minter

$ npx oz send-tx
? Pick a network development
? Pick an instance SimpleToken at 0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B
? Select which function addMinter(account: address)
? account (address): 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550
✓ Transaction successful. Transaction hash: 0x4f96f599171060e2d7ee2e924136a0f4c794bb70f51e65f1c82acfdbbee04d48
Events emitted:
 - MinterAdded(0xC89Ce4735882C9F0f0FE26686c53074E09B0D550)

Renounce the contract creator as a minter

$ npx oz send-tx
? Pick a network development
? Pick an instance SimpleToken at 0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B
? Select which function renounceMinter()
✓ Transaction successful. Transaction hash: 0xe16e1fec53e30f58079b07e65e50e048136a1ea4acb23c7d9a5f6d77478c2070
Events emitted:
 - MinterRemoved(0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1)

Purchase tokens

$ npx oz send-tx --value "1000000000000000000"
? Pick a network development
? Pick an instance SimpleCrowdsale at 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550
? Select which function buyTokens(beneficiary: address)
? beneficiary (address): 0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d
✓ Transaction successful. Transaction hash: 0x158002bc03c98c9f8c5916056e1a39139a78ae034d2024559d3e87f1818d72be
Events emitted:
 - TokensPurchased(0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1, 0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d, 1000000000000000000, 1000000000000000000)
1 Like