Hi @JasoonS,
Welcome to the community forum
. Thanks for posting your question here.
As an aside, you may want to consider using OpenZeppelin CLI directly, at least whilst you are developing your contract. I haven’t used truffle migrations much for OpenZeppelin SDK and find it easier to use the CLI to create contracts, and interact with them using send-tx
and call
.
I ran truffle migrate
and reproduced the error: Error: One or more contracts have validation errors.
I then ran an oz check
and got a warning that WildcardSteward_v0 sets an initial value in a field declaration.
$ oz check
✓ Compiled contracts with solc 0.5.12 (commit.7709ece9)
Compilation warnings:
contracts/ERC721Patronage_v0.sol:25:50: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
^-------------^
- Contract WildcardSteward_v0 or one of its ancestors sets an initial value in a field declaration. Consider moving all field initializations to an initializer function. See https://docs.openzeppelin.com/sdk/2.5/writing_contracts.html#avoid-initial-values-in-fields-declarations.
I also get the same warning if I do an oz create
$ oz create
Nothing to compile, all contracts are up to date.
? Pick a contract to instantiate WildcardSteward_v0
? Pick a network development
✓ Added contract WildcardSteward_v0
- Contract WildcardSteward_v0 or one of its ancestors sets an initial value in a field declaration. Consider moving all field initializations to an initializer function. See https://docs.openzeppelin.com/sdk/2.5/writing_contracts.html#avoid-initial-values-in-fields-declarations.
- Contract WildcardSteward_v0 or one of its ancestors sets an initial value in a field declaration. Consider moving all field initializations to an initializer function. See https://docs.openzeppelin.com/sdk/2.5/writing_contracts.html#avoid-initial-values-in-fields-declarations.
✓ Contract ERC721Patronage_v0 deployed
✓ Contract WildcardSteward_v0 deployed
✓ Contract WildcardSteward_v0 deployed
All contracts have been deployed
? Do you want to call a function on the instance after creating it? No
Possible initialization method (initialize) found in contract. Make sure you initialize your instance.
✓ Setting everything up to create contract instances
✓ Instance created at 0x4bf749ec68270027C5910220CEAB30Cc284c7BA2
0x4bf749ec68270027C5910220CEAB30Cc284c7BA2
Initial values in field declarations is the equivalent of setting values in a constructor which we can’t do for upgradable contracts, so either need to make these constants or set in the initialize
function. See the documentation for further details:
https://docs.openzeppelin.com/sdk/2.5/writing-contracts#avoid-initial-values-in-field-declarations
I removed the initial values from the declarations in WildcardSteward_v0
// 1200% patronage
uint256 patronageNumerator;
uint256 patronageDenominator;
and added them to the initialize
function
patronageNumerator = 12;
patronageDenominator = 1;
This then allows truffle migrate
to migrate successfully.