I have a logic contract (Box.sol) that can store/retrieve a value and I want to interact with it via a ERC1967Proxy
Problem: after updating once the box value directly, retrieving the value via the proxy returns the default value instead as it it was a different box instance
behavior: calling proxy.retrieve returns 0 (the default box value)
expected: calling proxy.retrieve returns 5 (the previously manually updated value)
this is what I do
- deploy logic contract (Box.sol) => stored value is 0
- interact with logic contract directly => stored value is updated (ex: 5)
- deploy proxy contract (MyProxy.sol) with logic contract address in the constructor
- With remix I retrieve the value with the proxy contract address by using the Box ABI (select Box.sol from file explorer tab, select "at address" button from transaction tab, but use the address of the proxy instead of the address of the deployed box)
Final Deployment status
Box.sol
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Box {
uint256 private _value;
// Emitted when the stored value changes
event ValueChanged(uint256 value);
// Stores a new value in the contract
function store(uint256 value) public {
_value = value;
emit ValueChanged(value);
}
// Reads the last stored value
function retrieve() public view returns (uint256) {
return _value;
}
}
MyProxy.sol
// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
contract MyProxy is ERC1967Proxy {
constructor(address _logic, bytes memory _data) ERC1967Proxy(_logic, _data) {}
// debug method to expose the address
function getImplementationAddress() public view returns(address) {
return ERC1967Upgrade._getImplementation();
}
}