Hi @casper,
Currently your deployment contract is upgradeable, and could potentially allow relayed transactions via the GSN (though extra code is required), whilst the token and crowdsale are not upgradeable.
Assuming that you want to create an upgradeable token and an upgradeable crowdsale, then I would suggest deploying them using the OpenZeppelin CLI.
If required you can create the contracts programmatically (see the documentation on Upgrading Contracts Programmatically)
See the following simple example of creating a crowdsale using the OpenZeppelin CLI:
SimpleToken.sol
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";
/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `ERC20` functions.
*/
contract SimpleToken is Initializable, ERC20, ERC20Detailed {
/**
* @dev Constructor that gives sender all of existing tokens.
*/
function initialize(address sender) public initializer {
ERC20Detailed.initialize("SimpleToken", "SIM", 18);
_mint(sender, 10000 * (10 ** uint256(decimals())));
}
}
SimpleCrowdsale.sol
pragma solidity ^0.5.0;
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/crowdsale/Crowdsale.sol";
contract SimpleCrowdsale is Initializable, Crowdsale {
function initialize(
uint256 rate, // rate in TKNbits
address payable wallet,
IERC20 token
) public initializer {
Crowdsale.initialize(rate, wallet, token);
}
}
Create the token
Tokens given to the sender
$ npx oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate SimpleToken
? 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(sender: address)
? sender (address): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
β Setting everything up to create contract instances
β Instance created at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
0xCfEB869F69431e42cdB54A4F4f105C19C080A601
Create the crowdsale
Rate of 1
$ npx oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate SimpleCrowdsale
? Pick a network development
β Added contract SimpleCrowdsale
β Contract SimpleCrowdsale deployed
All contracts have been deployed
? 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): 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
? token (address): 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
β Instance created at 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550
0xC89Ce4735882C9F0f0FE26686c53074E09B0D550
Transfer the total supply to the crowdsale
Get the total supply
$ npx oz call
? Pick a network development
? Pick an instance SimpleToken at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Select which function totalSupply()
β Method 'totalSupply()' returned: 10000000000000000000000
10000000000000000000000
Transfer the total supply
$ npx oz send-tx
? Pick a network development
? Pick an instance SimpleToken at 0xCfEB869F69431e42cdB54A4F4f105C19C080A601
? Select which function transfer(recipient: address, amount: uint256)
? recipient (address): 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550
? amount (uint256): 10000000000000000000000
β Transaction successful. Transaction hash: 0x6e088af3e5e142cbdf64df3942a2bc8f6437e84ccc4fb4659bb2ec1cbc664390
Events emitted:
- Transfer(0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1, 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550, 10000000000000000000000)
Buy 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): 0xd03ea8624C8C5987235048901fB614fDcA89b117
β Transaction successful. Transaction hash: 0x30cb6158224ab3d43651ff3cce9af0d4b0fc14cc89700d8adc1d38a6dbde5ca3
Events emitted:
- TokensPurchased(0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1, 0xd03ea8624C8C5987235048901fB614fDcA89b117, 1000000000000000000, 1000000000000000000)