Code to reproduce
constracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Box {
uint256 private value;
// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}
}
scripts/1.deploy_box.ts
import { ethers } from "hardhat"
import { upgrades } from "hardhat"
async function main() {
const Box = await ethers.getContractFactory("Box")
console.log("Deploying Box...")
const box = await upgrades.deployProxy(Box,[42], { initializer: 'store' })
const boxAddress = await box.getAddress()
console.log(boxAddress," box(proxy) address")
console.log(await upgrades.erc1967.getImplementationAddress(boxAddress)," getImplementationAddress")
console.log(await upgrades.erc1967.getAdminAddress(boxAddress)," getAdminAddress")
// changeProxyAdmin
const votingContractAddress = '0xdd44f0e4cd2dd7a5b341460e86878e3294264036'
upgrades.admin.changeProxyAdmin(boxAddress, votingContractAddress)
}
main().catch((error) => {
console.error(error)
process.exitCode = 1
})
hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import '@openzeppelin/hardhat-upgrades';
const { vars } = require("hardhat/config");
const config: HardhatUserConfig = {
solidity: "0.8.24",
networks: {
holesky: {
url: `https://rpc.holesky.ethpandaops.io`,
accounts: [vars.get('HOLESKY_PRIVATE_KEY')]
}
}
};
export default config;
deploy the contract : yarn hardhat run scripts/1.deploy_box.ts --network holesky