Last active
October 11, 2022 02:59
-
-
Save ImHukam/53a45d621032ce0cb1e7d44ac1d133f3 to your computer and use it in GitHub Desktop.
zkevm_proxy_upgradable_contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hre = require("hardhat"); | |
const { ethers } = require("ethers"); | |
const matic_provider = new ethers.providers.JsonRpcProvider("https://internal.zkevm-test.net:2083") | |
const abi = [ | |
"function value() public view returns(uint256)", | |
"function set_value(uint256 _val) public", | |
"function value_inc() public" | |
]; // abi of implementation contract | |
const address = ""; // proxy address | |
const tokenContract = new ethers.Contract(address, abi, matic_provider); | |
const privateKey = ""; // only for testing purpose, use env for real development | |
const matic_wallet = new ethers.Wallet(privateKey, matic_provider); | |
const tokenContractWtihWallet = tokenContract.connect(matic_wallet); | |
async function main() { | |
const value = await tokenContractWtihWallet.value(); | |
console.log(value.toString()) | |
// const set_value= await tokenContractWtihWallet.set_value('6') | |
// await set_value.wait(); | |
const value_inc = await tokenContractWtihWallet.value_inc(); | |
await value_inc.wait(); | |
const new_value = await tokenContractWtihWallet.value(); | |
console.log(new_value.toString()) | |
} | |
main() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
contract TEST is Initializable, OwnableUpgradeable { | |
uint256 val; | |
function initialize() public initializer { | |
__Ownable_init_unchained(); | |
} | |
function value() public view returns (uint256) { | |
return val; | |
} | |
function set_value(uint256 _val) public onlyOwner { | |
val= _val; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { upgrades, ethers } = require("hardhat"); | |
async function main() { | |
const Contract = await ethers.getContractFactory("TEST"); | |
const contract = await upgrades.deployProxy(Contract); | |
await contract.deployed(); | |
console.log("deployed to:", contract.address); | |
} | |
main() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { upgrades, ethers } = require("hardhat"); | |
const proxyAddress = "0x56d1D1351D15969ad7b4571e6c8564E16E926b2f"; | |
async function main() { | |
const Contract = await ethers.getContractFactory("TEST_V2"); | |
const contract = await upgrades.upgradeProxy(proxyAddress, Contract); | |
await contract.deployed(); | |
console.log("deployed to:", contract.address); | |
} | |
main() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | |
contract TEST_V2 is Initializable, OwnableUpgradeable { | |
uint256 val; | |
function initialize() public initializer { | |
__Ownable_init_unchained(); | |
} | |
function value() public view returns (uint256) { | |
return val; | |
} | |
function set_value(uint256 _val) public onlyOwner { | |
val= _val; | |
} | |
//new funcion | |
function value_inc() public onlyOwner{ | |
val= val + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment