# UpgradeableContracts **Repository Path**: dongyanggl/upgradeable-contracts ## Basic Information - **Project Name**: UpgradeableContracts - **Description**: 可升级合约 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-10-26 - **Last Updated**: 2023-10-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UpgradeableContracts 参考 https://www.quicknode.com/guides/ethereum-development/smart-contracts/how-to-create-and-deploy-an-upgradeable-smart-contract-using-openzeppelin-and-hardhat https://medium.com/coinmonks/beginners-guide-to-transparent-proxy-pattern-f40d6085bf3c ## 初始化 ``` npm init -y npm install --save-dev @openzeppelin/hardhat-upgrades npm install --save dotenv npx hardhat ``` ### 部署测试网 ``` npx hardhat run scripts/deploy.js --network goerli npx hardhat verify --network goerli 0x0165878A594ca255338adfa4d48449f69242Eb8F 参数1 参数2 ``` ### 运行本地链 上面的方式部署合约只在当前的运行环境中有效,要能够模拟本地上链,需要在运行本地链 ``` npx hardhat node ``` ### 部署本地 ``` npx hardhat run scripts/deploy.js --network localhost ``` ## proxydemo 1. 部署和验证 V1 合约 ``` npx hardhat run scripts/deployV1.js --network goerli npx hardhat verify --network goerli 0x0165878A594ca255338adfa4d48449f69242Eb8F ``` 可以在链上交互合约,交互之前在链上需要根据提示关联 proxy 2. 升级到 V2 合约 ``` npx hardhat run scripts/deployV2.js --network goerli npx hardhat verify --network goerli 0x0165878A594ca255338adfa4d48449f69242Eb8F ```