当前位置:网站首页>solidity部署和验证代理合约
solidity部署和验证代理合约
2022-06-29 06:48:00 【【03】】
相关合约
使用openzeppelin的两个代理辅助合约
TransparentUpgradeableProxy.sol
地址
openzeppelin-contracts/contracts/proxy/transparent at master · OpenZeppelin/openzeppelin-contracts
部署逻辑合约
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Web03{
constructor() public {
}
string public constant url = 'web03.cn';
mapping (uint => string) public names;
uint public namesN;
function addName(string memory _name) public {
names[namesN++] = _name;
}
}
交易地址:
https://rinkeby.etherscan.io/tx/0xd11215fa054742276d378917b76093b51dd74124735d8bfffe14928f25d0fc07
合约地址:0xd37C4f32816Ac29a839ca2a854726432080D14c4
部署管理合约ProxyAdmin.sol
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/transparent/ProxyAdmin.sol";
contract Web03ProxyAdmin is ProxyAdmin{
constructor() {
}
}
交易地址:https://rinkeby.etherscan.io/tx/0xfabbdfb4fc9a0c0196a04d3fd1bfceafc23cc78e0351155a71415b37b91bd4b2
合约地址:0x60db1202a8c2d2b60d628a03741fed1920bf25f2
部署代理合约TransparentUpgradeableProxy.sol
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
contract Web03Proxy is TransparentUpgradeableProxy{
constructor(address _logic,address admin_,bytes memory _data) TransparentUpgradeableProxy(_logic, admin_, _data){
}
}
参数解析
- address _logic 逻辑合约地址【0xd37C4f32816Ac29a839ca2a854726432080D14c4】
- address admin_ 管理合约地址【0x60db1202a8c2d2b60d628a03741fed1920bf25f2】
- bytes memory _data 发布逻辑合约时的参数字节码,0x表示无参数【0x】
交易地址:https://rinkeby.etherscan.io/tx/0xbeb7bf1cae9b8c37035fd251080baefb9fb1d9d72c5498997685c2a429af1318
合约地址:0x82f4728Aa261eBd7887367096BCA4C15356CF188
验证合约
为了看到直观效果,选择验证合约
如何验证请查看往期文章《solidity合约验证》:https://web03.cn/blog/299
验证之后区块链浏览器在代理合约看不到逻辑合约的方法?
在 代码tab 选择More Option 再选择Is this a proxy?

他会自动找到你的逻辑合约,点击Verify即可

升级合约
-调用合约存数据,预验证代理数据-
先调用代理合约方便验证代理功能
调用addName,往里面添加一组数据

此时,names方法也是可以查到

1、发布新的逻辑合约
contract Web03V2{
constructor() {
}
string public constant url = 'web03.cn';
mapping (uint => string) public names;
uint public namesN;
uint public constant D = 1;
function addName(string memory _name) public {
names[namesN++] = _name;
}
function addD(uint _d) public pure{
D + _d;
}
}
交易地址:https://rinkeby.etherscan.io/tx/0x887c2d2a5f7ebdf1c1b27902a7a03b3cb4da87102797a941909b93c595b09cbb
合约地址:0xdFEaA297C19622892a07e4Da428b377aDA10f0AD
2、调用升级方法
调用管理合约方法
- upgrade,需要传入(代理合约地址,新的逻辑合约地址)
- upgradeAndCall,需要传入(代理合约地址,新的逻辑合约地址,初始化调用数据,支付金额)
当前升级未涉及初始化数据和支付金额,所以调用upgrade即可
upgrade(0x82f4728Aa261eBd7887367096BCA4C15356CF188, 0xdFEaA297C19622892a07e4Da428b377aDA10f0AD)
升级交易地址:https://rinkeby.etherscan.io/tx/0x9de289d9a3fb021cdb04fa08301a706c3a7e1b52da5aa5c9f13cfb812c775a9f
-升级后,查看并验证数据-

可以看到,升级后的合约新加的方法D和方法addD都已经出现(addD书写错误,忽略,但是不影响)
查询names[0]=零三
升级前的数据依旧保留,说明代理成功
- 数据是存在代理合约的,这份数据在部署代理时初始化,后面只更改了逻辑合于地址,SO 数据一直保存着
边栏推荐
猜你喜欢

低配MySQL数据库几十秒插入百万数据

Prompt during packaging: property 'sqlsessionfactory' or 'sqlsessiontemplate'‘

Common MySQL errors and solutions summarized painstakingly (II)

C实战——高配版贪吃蛇游戏设计

穿越过后,她说多元宇宙真的存在

C#Mqtt订阅消息

Vulnhub's dc7 target
![Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200](/img/56/b300c0c3606dbc328e301092615bff.jpg)
Detailed explanation of communication principle between [industrial control old horse] single chip microcomputer and Siemens S7-200

SizeBalanceTree

基于Sophus的Ceres优化
随机推荐
Program debugging - debug/release version
[repair collection function, update login interface] knowledge payment applet, blog applet, full version open source code, resource realization applet, with 299 whole station resource data
Detailed design of PLC program control system for washing machine
Sonic communication - streaming data processing - window alignment
What are the organizational structure and job responsibilities of product managers in Internet companies?
ROS当中的仿真时间以及Bag包操作
Up and down transitions in polymorphism
SizeBalanceTree
MongoDB-使用mongo/mongosh命令行连接数据库
【修复收藏功能、更新登录接口】知识付费小程序、博客小程序、完整版开源源码、资源变现小程序,带299整站资源数据
Detailed explanation of route (Jiuyang Scripture)
Qtcreator set character set
Django - installing mysqlclient error: mysqlclient 1.4.0 or newer is required; you have 0.9.3
Should product managers learn from ink knife or Axure?
Code:: blocks code formatting shortcuts
Process communication - Pipeline
nor flash 应用层操作
JSP learning part
基础语法 - 位运算
Vulnhub's dc6 target