I’m following this great tutorial: OpenZeppelin Upgrades: Step by Step Tutorial for Truffle
Here are my deployed contracts, so far so good.
-
Migrations:
https://rinkeby.etherscan.io/address/0x8d11f5d53f8efc86be553d5298a4115b6b3c224a#code
-
Box:
https://rinkeby.etherscan.io/address/0xc5097c49f4f59c1df18b4320bda9c7a74031a3d8#code
-
ProxyAdmin:
https://rinkeby.etherscan.io/address/0x899fc2cb368daa3fe1ff852ba367a9e2f9bb1afa#code
-
AdminUpgradeabilityProxy:
https://rinkeby.etherscan.io/address/0x35937192e3185bd137a899f85d5f2543bc881bc1#code
-
BoxV2:
https://rinkeby.etherscan.io/address/0x637f5818b98366ca3f8595a2e09297ad4840e7b5#code
I’m able to send a transaction from my front-end to BoxV2, it works, it increments the counter.
Link to the live code: https://plnkr.co/edit/EpzPkHKp0gzPi0Ui?open=lib%2Fscript.js
<!doctype html>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js'></script>
<script src="https://cdn.jsdelivr.net/npm/ethers@5.0.17/dist/ethers.umd.js" type="text/javascript"></script>
<script>
var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
$scope.increment = function() {
console.log("increment")
contract.increment();
}
});
</script>
</head>
<body ng-app="app" ng-controller="ctrl">
<button ng-click="increment()">Call increment()</button>
</body>
<script>
ABI = [{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"ValueChanged","type":"event"},{"inputs":[],"name":"increment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}];
// address = "0x35937192e3185bd137a899F85d5F2543bc881bC1"; // AdminUpgradeabilityProxy
address = "0x637f5818b98366ca3f8595a2e09297ad4840e7b5"; // BoxV2
async function init() {
await window.ethereum.enable();
const provider = new ethers.providers.Web3Provider(window.ethereum)
let network = await provider.getNetwork(); console.log(network);
signer = provider.getSigner();
contract = new ethers.Contract(address, ABI, signer);
}
init();
</script>
</html>
BUT
The whole point of proxy upgradeable pattern:
- I keep the
proxy
address stable - I upgrade the
implementation
When I call increment()
on AdminUpgradeabilityProxy
and then retrieve
on BoxV2
it does not get updated…
See this transaction: https://rinkeby.etherscan.io/tx/0xbc15bed9b3b5d75d37a6202a5f376ea1cce43cce22ea40e14db16d342cf348ce
The counter in BoxV2
wasn’t incremented that way… What is the proxy
address I should use?