ERC20 Contract is initialized now how do I set initial supply of tokens

Hi again,

I have deployed a contract to ropsten network using truffle.
I got two contracts deployed


and

I felt I have achieved big step, however I realized that I didn’t provide total supply.
Since this code is a taken from github from paxos-contract and there is no total supply provided.

It is also mentioned that it is mintable and one comment is code says that
“This contract is a Pausable ERC20 token with Burn and Mint controlled by a central SupplyController. By implementing PaxosImplementation this contract also includes external methods for setting a new implementation contract for the Proxy.”

I have checked how to mint the tokens but everytime I get only function as what to call but nowhere mentioned that how to call or use that function. Should it be in truffle console, or some js file or new contract.

In short, I like to know how to add initial total supply, how do I mint and how to I use proxy to upgrade the contract.

This is too much to ask but any example would be great to start with.

Thanks
Rags

1 Like

Hi @Raghav_Lyon,

Well done on deploying contracts to Ropsten.

The following example is for an upgradeable mintable ERC20 token and an upgradeable Minted Crowdsale. (I have created a few different types of examples in the forum if you are after something specific, I may have already created one that I can point you to).

With a Mintable Token the total supply is initially zero until you mint tokens (unless you mint tokens in the initializer).

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

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)

Thank you for quick response Andrew.
I will try this and update here soon.
I may be having few more questions if things didn’t go well with me.

1 Like

Feel free to ask all the questions that you need.

I recommend reading through the documentation on Crowdsales:
https://docs.openzeppelin.com/contracts/2.x/crowdsales

I also recommend creating ERC20 token and Crowdsale contracts and interacting with the CLI to help get an understanding of how they work.

Thank you again Andrew.

1 Like

A post was split to a new topic: Send ERC20 tokens to other address “Fail with error ‘whenNotPaused’”