[Deployment] Deploying Beacon Proxy Upgradeable Simple ERC20 Contract #221
-
EnvironmentTestnet zkSolc Version1.3.17 zksync-web3 Versionzksync2-js ^0.2.2 Hardhat.config.tsimport { HardhatUserConfig } from "hardhat/config";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-upgradable";
const config: HardhatUserConfig = {
defaultNetwork: "zkSyncTestnet",
networks: {
zkSyncTestnet: {
zksync: true,
url: "https://testnet.era.zksync.dev",
ethNetwork: "goerli",
},
zkSyncMainnet: {
url: "https://mainnet.era.zksync.io",
ethNetwork: "mainnet",
zksync: true,
},
dockerizedNode: {
url: "http://localhost:3050",
ethNetwork: "http://localhost:8545",
zksync: true,
},
inMemoryNode: {
url: "http://127.0.0.1:8011",
ethNetwork: "",
zksync: true,
},
hardhat: {
zksync: true,
},
},
zksolc: {
version: "1.3.17",
settings: {
// find all available options in the official documentation
// https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html#configuration
},
},
solidity: {
version: "0.8.20",
},
};
export default config; Deployment Script (WITHOUT PRIVATE KEY)import {Provider, Wallet,} from "zksync2-js";
import {Deployer} from "@matterlabs/hardhat-zksync-deploy";
import * as hre from "hardhat";
require('dotenv').config();
async function main() {
const rpcUrl = hre.network.config.url;
const provider = new Provider(rpcUrl);
console.log(`RPC URL: ${rpcUrl}`);
const zkWallet = new Wallet(process.env.WALLET_PRIVATE_KEY!);
console.log(`Wallet address: ${zkWallet.address}`);
const deployer = new Deployer(hre, zkWallet);
const contractName = "Gus";
const contract = await deployer.loadArtifact(contractName);
const beacon = await hre.zkUpgrades.deployBeacon(deployer.zkWallet, contract);
await beacon.deployed();
console.log("Beacon deployed to:", beacon.address);
const gus = await hre.zkUpgrades.deployBeaconProxy(deployer.zkWallet, beacon, contract, [0]);
await gus.deployed();
console.log(contractName + " beacon proxy deployed to: ", gus.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
}); Contract Code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract Gus is Initializable, ERC20Upgradeable, OwnableUpgradeable {
function initialize() initializer public {
__ERC20_init("Gussiiii", "GUS");
__Ownable_init();
_mint(msg.sender, 200000 * 10 ** decimals());
}
function decimals() public pure override returns (uint8) {
return 2;
}
// another functions
} Does this work on other EVMs? (If yes, please list at least 1 of them)Polygon, ZkSync (without proxy) Description of What Your Contract DoesSimple ERC20 Token. Burn, Mint. Repo Link (Optional)No response Additional DetailsI want to deploy a simple ERC20 token contract using the proxy pattern as recommended documentation. I use hardhat-zksync-upgradeable plugin (1.0.0) and beacon proxy. Also, I use the simple example of deploying script from docks https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-upgradable.html#full-code-for-deploy-beacon In an example from docks using zksync-web3, but last version of hardhat-zksync-deploy working with zksync2-js. const beacon = await hre.zkUpgrades.deployBeacon(deployer.zkWallet, contract); Error:
Here is my package list: "devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "^1.0.0",
"@matterlabs/hardhat-zksync-upgradable": "^1.0.0",
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "4.9.2",
"dotenv": "^16.0.3",
"ethers": "^6.9.0",
"hardhat": "^2.19.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"zksync2-js": "^0.2.2"
} How can I fix it? Are somewhere examples with new versions of packages? Or what versions I must use for successful deploy by example in docks? Thanks for answers |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hey @vascovitche 👋 , Thanks for reaching out. In the example you shared the are a couple of issues with the dependency versions and the deployment script. To make it work, I changed the dependencies to the following: "devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "^1.0.0",
"@matterlabs/hardhat-zksync-upgradable": "^1.0.0",
"@openzeppelin/contracts": "^4.9.2",
"@openzeppelin/contracts-upgradeable": "^4.9.2",
"dotenv": "^16.0.3",
"ethers": "^6.9.0",
"hardhat": "^2.19.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"zksync-ethers": "^6.1.0"
} and modified the deployment script based on our import { Wallet } from "zksync-ethers";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import * as hre from "hardhat";
require('dotenv').config();
async function main() {
const zkWallet = new Wallet(process.env.WALLET_PRIVATE_KEY!);
console.log(`Wallet address: ${zkWallet.address}`);
const deployer = new Deployer(hre, zkWallet);
const contractName = "Box";
const contract = await deployer.loadArtifact(contractName);
const beacon = await hre.zkUpgrades.deployBeacon(deployer.zkWallet, contract);
await beacon.waitForDeployment();
const beaconAddress = await beacon.getAddress();
const gus = await hre.zkUpgrades.deployBeaconProxy(deployer.zkWallet, beaconAddress, contract);
await gus.waitForDeployment();
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
}); Feel free to check the full example here. |
Beta Was this translation helpful? Give feedback.
Hey @vascovitche 👋 ,
Thanks for reaching out. In the example you shared the are a couple of issues with the dependency versions and the deployment script. To make it work, I changed the dependencies to the following:
and modified the deployment script based on our
hardhat-zksync-upgradable
tutorial here: