I am trying to create a sample upgradable proxy contract deployment and have the following.
Math.sol
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract Math is Initializable, UUPSUpgradeable, OwnableUpgradeable {
function initialize() public initializer {
__Ownable_init();
__UUPSUpgradeable_init();
}
function doSum(uint a, uint b) public pure returns (uint sum) {
return a + b;
}
function _authorizeUpgrade(address) internal override onlyOwner {}
}
hardhat.config.js
require('dotenv').config();
require("@nomiclabs/hardhat-waffle");
require('@openzeppelin/hardhat-upgrades');
require("@nomiclabs/hardhat-etherscan");
const { ROPSTEN_API_URL, PRIVATE_KEY, ETHERSCAN_API_KEY } = process.env;
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.4",
defaultNetwork: "hardhat",
networks: {
hardhat: {},
ropsten: {
url: ROPSTEN_API_URL,
accounts: [`0x${PRIVATE_KEY}`],
},
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: ETHERSCAN_API_KEY
}
};
I run npx hardhat compile
, which compiles everything fine as can be seen below
$ npx hardhat compile
Compiling 1 file with 0.8.4
Solidity compilation finished successfully
✨ Done in 1.89s.
deploy.js
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const { ethers, upgrades } = hre;
async function main() {
// Hardhat always runs the compile task when running scripts with its command
// line interface.
//
// If this script is run directly using `node` you may want to call compile
// manually to make sure everything is compiled
// await hre.run('compile');
// We get the contract to deploy
const Math = await hre.ethers.getContractFactory("Math");
const instance = await upgrades.deployProxy(Math, { kind: 'uups' });
await instance.deployed();
console.log("Math Proxy deployed to:", instance.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
When running the deploy script, my contract deploys completely fine but when I replace the deployproxy code to use the following
const instance = await upgrades.upgradeProxy('0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512', Math, { kind: 'uups' })
console.log("Math Contract Upgraded");
I get the following error
Contract at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 doesn't look like an administered ERC 1967 proxy
I'm not sure what is going on. Please let me know if I am doing something wrong or need to contact folks over at hardhat