I’m unable to compile a simple Upgradable ERC20 contract. It works fine with a vanilla ERC20 both provided by OpenZeppelin.
Environment
Windows 10
WSL2
Truffle v5.1.55
Node v10.19.0
Ganache
Details
When trying to migrate the contract using npx truffle migrate --network development
I’m receiving the below output.
❯ npx truffle migrate --network development
Compiling your contracts...
===========================
> Compiling ./contracts/ZCX.sol
> Artifacts written to /home/vito/code/erc20/build/contracts
> Compiled successfully using:
- solc: 0.7.5+commit.eb77ed08.Emscripten.clang
Starting migrations...
======================
> Network name: 'development'
> Network id: 1607010901216
> Block gas limit: 6721975 (0x6691b7)
2_deploy_token.js
===========
Error: The requested contract was not found. Make sure the source code is available for compilation
at getContractNameAndRunValidation (/home/vito/code/erc20/node_modules/@openzeppelin/upgrades-core/src/validate.ts:157:11)
at Object.assertUpgradeSafe (/home/vito/code/erc20/node_modules/@openzeppelin/upgrades-core/src/validate.ts:195:26)
at deployProxy (/home/vito/code/erc20/node_modules/@openzeppelin/truffle-upgrades/src/deploy-proxy.ts:49:3)
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.1.55 (core: 5.1.55)
Node v10.19.0
Code to reproduce
MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
contract MyToken is Initializable, ERC20Upgradeable {
function initialize(string memory name, string memory symbol, uint256 initialSupply) public virtual initializer {
__ERC20_init(name, symbol);
_mint(_msgSender(), initialSupply);
}
}
2_deploy_token.js
// migrations/2_deploy_token.js
const MyToken = artifacts.require('MyToken');
const { deployProxy } = require('@openzeppelin/truffle-upgrades');
module.exports = async function (deployer) {
await deployProxy(MyToken, ['My Token', 'TKN', '100000000000000000000000'], { deployer, initializer: 'initialize' });
};