openzeppelin check error
TypeError: Member “initialize” not found or not visible after argument-dependent lookup in address.
newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, _owner, _owner);
I changed the minter and pauser parameters to provide an empty array of addresses, as previously this was a single address.
pragma solidity >=0.5.0 <0.7.0;
/// dependencies
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/lifecycle/Pausable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/StandaloneERC20.sol";
contract STFactory is Initializable, Ownable, Pausable {
using SafeMath for uint256;
/// states
address stFactoryOwner;
uint8 public constant DECIMALS = 18;
uint256 public constant INITIALSUPPLY = 1 * (10 ** uint256(DECIMALS));
/// functions
/// initialize function
function initialize(address owner) public initializer {
stFactoryOwner = owner;
Pausable.initialize(stFactoryOwner);
}
/// deployToken function
function deployToken(
string calldata _ticker,
string calldata _name,
address _owner
)
external
returns(address)
{
address tokenAddress = _deployToken(
_ticker,
_name,
_owner
);
return tokenAddress;
}
/// _deployToken internal function
function _deployToken(
string memory _ticker,
string memory _name,
address _owner
)
internal
returns(address)
{
/// intantiate ERC20
StandaloneERC20 newStandaloneERC20 = new StandaloneERC20();
newStandaloneERC20.initialize(_name, _ticker, DECIMALS, INITIALSUPPLY, _owner, new address[](0), new address[](0));
return address(newStandaloneERC20);
}
}
Create Factory
$ oz create
âś“ Compiled contracts with solc 0.5.11 (commit.c082d0b4)
? Pick a contract to instantiate STFactory
? Pick a network development
- Variable _pausers (PauserRole) contains a struct or enum. These are not automatically checked for storage compatibility in the current version. See https://docs.openzeppelin.com/sdk/2.5/writing_contracts.html#modifying-your-contracts for more info.
âś“ Contract STFactory deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(owner: address)
? owner (address): 0x13ebd3443fa5575F0Eb173e323D8419F7452CfB1
âś“ Setting everything up to create contract instances
âś“ Instance created at 0x630589690929E9cdEFDeF0734717a9eF3Ec7Fcfe
0x630589690929E9cdEFDeF0734717a9eF3Ec7Fcfe
Deploy Token
$ oz send-tx
? Pick a network development
? Pick an instance STFactory at 0x630589690929E9cdEFDeF0734717a9eF3Ec7Fcfe
? Select which function deployToken(_ticker: string, _name: string, _owner: address)
? _ticker (string): My Token
? _name (string): TKN
? _owner (address): 0x13ebd3443fa5575F0Eb173e323D8419F7452CfB1
âś“ Transaction successful. Transaction hash: 0xb899f41b80e745cd34654883f87bb3c037a681c6cddb28c12bd7fc053cfe8167
Events emitted:
- PauserAdded(0x61d47DA73822B4a77c4a9Bae56Ba25729669b9F1)
- PauserRemoved(0x61d47DA73822B4a77c4a9Bae56Ba25729669b9F1)
You could create a registry contract and programmatically create tokens and update the registry, though that doesn't sound better than using an on-chain factory.
Please be aware that the tokens created via the factory are not upgradeable whilst the tokens created via the CLI can be upgraded.
You’re such a rock star mate.
Thank you @abcoathup the recent changes work.
Create Contract
$ oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate STFactory
? Pick a network development
All contracts are up to date
? Do you want to call a function on the instance after creating it? Yes
? Select which function * initialize(_owner: address)
? _owner (address): 0xf1a6D546A5baa618ebEBBE37f10be668239bE20e
âś“ Instance created at 0x591db31df99717845B53e3Fe58Bbd973CFfcF398
0x591db31df99717845B53e3Fe58Bbd973CFfcF398
Deploy Token
$ oz send-tx
? Pick a network development
? Pick an instance STFactory at 0x591db31df99717845B53e3Fe58Bbd973CFfcF398
? Select which function deployToken(_ticker: string, _name: string, _owner: address)
? _ticker (string): ABC
? _name (string): ABC
? _owner (address): 0xf1a6D546A5baa618ebEBBE37f10be668239bE20e
âś“ Transaction successful. Transaction hash: 0x4768347d816ebfdf32cceb8a280760c1d1c9c9da79503b09dd9538887e7cedda
Events emitted:
- PauserRemoved(0x19Fc5dE13D76ead5B622c9B73DA37cD48ceb1181)
- TokenDeployed(0x19Fc5dE13D76ead5B622c9B73DA37cD48ceb1181)
Check Balance 1
$ oz balance
? Enter an address to query its balance 0xf1a6D546A5baa618ebEBBE37f10be668239bE20e
? Pick a network development
Balance: 99.7921448 ETH
99792144800000000000
Check Balance 2
$ oz balance
? Enter an address to query its balance 0x19Fc5dE13D76ead5B622c9B73DA37cD48ceb1181
? Pick a network development
Balance: 0 ETH
0
How can I check the ERC20 token balance? Is there a oz CLI command?
Also thanks for the suggestion on Registry contract – I am almost finished building one, will post soon. But I want to call the oz CLI from this Registry contract, such that the new contracts/tokens are upgradeable (if needed).
Currently there isn’t an OpenZeppelin CLI command to interact with contracts not created via the CLI.
I created a new truffle based project, so I could use truffle console and initialized it with truffle and openzeppelin.
npm init -y
npm i truffle
npx truffle init
oz init
oz link @openzeppelin/contracts-ethereum-package
npm i @openzeppelin/upgrades
I added the factory contract to the project in my IDE.
I updated truffle-config.js to uncomment out the development network.
I then created the factory contract and deployed a new token (copying the address emitted from the event) using the OpenZeppelin CLI
$ oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate STRegister
? Pick a network development
âś“ Added contract STRegister
âś“ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-1568869704928
âś“ Contract STFactory deployed
âś– Validating and deploying contract STRegister
STRegister deployment failed with error: Returned error: VM Exception while processing transaction: out of gas
Colour Commentary
Looks like it doesn’t like something – STFactory is deployed, but STRegistry ran out of gas.
I only used Truffle and OpenZeppelin as that is the last project I had around with your code in. You should be fine with OpenZeppelin CLI by itself, you probably just need to increase the gas limit.