Create/Deploying Upgradable Contract Error

First, the docs indicate one should use create to… “publish” Contracts, but the CLI says:
The create command is deprecated. Use deploy instead.

:memo:Details
My actual issue is in attempting to deploy a Contract, this is my progression:

[21:38:51] [eviljordan@WAT ../xxxContract]$ npx oz deploy
✓ Compiled contracts with solc 0.6.7 (commit.b8d736ae)
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy xxxContract
Contract Token not found

What’s the deal with that last line, saying Contract Token not found? There is no file or Contract named “Token” in my project. Deploying as regular works fine.

:computer: Environment
OpenZeppelin 2.8.2
OpenZeppelin Contracts 3

1 Like

Hi @EvilJordan,

Sorry about the documentation. I have created an issue to update the documentation to use oz deploy: https://github.com/OpenZeppelin/docs.openzeppelin.com/issues/215

I am not sure why you are seeing Contract Token not found
Are you able to share a cut down version of your contract (including imports and inheritance) and I can try to reproduce?

Also, if you are creating upgradeable contracts and wanting to use OpenZeppelin Contracts then you need to use OpenZeppelin Contracts Ethereum Package. This is because we can’t use constructors in upgradeable contracts and need to use initializers. (See Limitations of Contract Upgrades for details)

OpenZeppelin Contracts Ethereum Package v3.0 has been released which uses Solidity 0.6.

Thanks for the reply!

Here it is, super-stripped down, same problem:

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract myToken is ERC721, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721("myToken", "MTK") public {
        _setBaseURI('https://myToken.com/');
    }

    function createToken(address tokenOwner) public onlyOwner returns (uint256) {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(tokenOwner, newItemId);

        return newItemId;
    }

}
1 Like

I’m gonna guess it has something to do with this section: https://docs.openzeppelin.com/learn/upgrading-smart-contracts#initialization and my inability to follow directions.

1 Like

Hi @EvilJordan,

The error that you are seeing is for a contract called Token. I assume you originally had a contract named Token in your project, that you deleted or removed the solidity but it is still in the OpenZeppelin CLI config.

To resolve, you can remove from the config using:

npx oz remove Token

When I deploy, (aside from a load of SPDX license identifier warnings), the CLI errors show that the contract has a constructor (which we can’t use in an upgradeable contract) and advises to use @openzeppelin/contracts-ethereum-package

$ npx oz deploy
✓ Compiled contracts with solc 0.6.8 (commit.0bbfe453)
Compilation warnings:
@openzeppelin/contracts/GSN/Context.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/access/Ownable.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/introspection/ERC165.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/introspection/IERC165.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/math/SafeMath.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/token/ERC721/ERC721.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/token/ERC721/IERC721.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/utils/Address.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/utils/Counters.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/utils/EnumerableMap.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/utils/EnumerableSet.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

@openzeppelin/contracts/utils/Strings.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

contracts/myToken.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.

? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy myToken
✓ Added contract myToken
- Contract myToken or an ancestor has a constructor. Change it to an initializer function. See https://docs.openzeppelin.com/upgrades/2.6//writing-upgradeable#initializers.
- Contract myToken imports token/ERC721/ERC721.sol, GSN/Context.sol, token/ERC721/IERC721.sol, introspection/IERC165.sol, token/ERC721/IERC721Metadata.sol, token/ERC721/IERC721Enumerable.sol, token/ERC721/IERC721Receiver.sol, introspection/ERC165.sol, math/SafeMath.sol, utils/Address.sol, utils/EnumerableSet.sol, utils/EnumerableMap.sol, utils/Strings.sol, access/Ownable.sol, utils/Counters.sol from @openzeppelin/contracts. Use @openzeppelin/contracts-ethereum-package instead. See https://docs.openzeppelin.com/cli/2.6/dependencies#linking-the-contracts-ethereum-package.
One or more contracts have validation errors. Please review the items listed above and fix them, or run this command again with the --force option.

You could deploy an upgradeable Preset ERC721 contract (logic contracts have already been deployed):

$ npx oz link @openzeppelin/contracts-ethereum-package
✓ Dependency @openzeppelin/contracts-ethereum-package installed
Dependency linked to the project. Run 'openzeppelin deploy' to deploy one of its contracts.

$ npx oz deploy
No contracts found to compile.
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy @openzeppelin/contracts-ethereum-package/ERC721PresetMinterPauserAutoIdUpgradeSafe
✓ Deploying @openzeppelin/contracts-ethereum-package dependency to network dev-1589774496346
All implementations are up to date
? Call a function to initialize the instance after creating it? Yes
? Select which function initialize(name: string, symbol: string, baseURI: string)
? name: string: My Token
? symbol: string: MYT
? baseURI: string: https://example.com/api/token/
✓ Setting everything up to create contract instances
✓ Instance created at 0x0E696947A06550DEf604e82C26fd9E493e576337
To upgrade this instance run 'oz upgrade'
0x0E696947A06550DEf604e82C26fd9E493e576337

This is exactly right. Thank you for the steps to fix :tada:, but wondering why a fresh deploy wouldn’t overwrite any existent configs? I assume it’s this part of the project.json (it is, I manually edited and tested):

"contracts": {
    "Token": "Token",
    "myToken": "myToken"
  }

Regarding the Preset ERC721 contract, is the idea here that, instead of importing ERC721 and other OZ-created contracts in myToken.sol, just link out to the already deployed versions?

Edit: Re: my preset question, the answer is yes. I can read!

As an aside, the compiler is referencing links for documentation v2.6 even though the compiler is v2.8.

1 Like

Hi @EvilJordan,

As you found, the contracts are kept in project.json.

I really like the Preset contracts. They can be deployed without any Solidity code being written and cover many use cases. (e.g. Create an ERC20 without writing Solidity, using OpenZeppelin CLI). We can use the CLI to deploy upgradeable versions (we just deploy the proxy and proxy admin as the logic contract is already deployed).

I created an Issue for the documentation: https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1540

I created a PR: https://github.com/OpenZeppelin/docs.openzeppelin.com/pull/222 to update the docs to change form oz create to oz deploy