Help with manually deployed ERC1976Proxy.sol and BoxV2.sol #1873
-
I'm trying to understand how proxies really work by deploying simple ones myself on Remix. I know Remix comes with "Deploy with Proxy" but I want to manually do it. My aim is to deploy I'm not getting any return value in Remix transaction. ![]() Steps I'm taking:
This seems to be not working. Am I missing some steps? My code: //SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract BoxV2 is Initializable, OwnableUpgradeable, UUPSUpgradeable {
uint256 internal number;
// this is a constructor which disables constructors. See BoxV1
/// @custom:oz-upgrades-unsafe-allow-constructor
constructor() {
_disableInitializers();
}
function initialize() public initializer {
__Ownable_init(msg.sender); // sets owner to msg.sender
__UUPSUpgradeable_init(); // doesn't do anything but it just says "hey this is UUPS upgradeable and we're gonna treat it as such"
}
function setNumber(uint256 _number) external {
number = _number;
}
function getNumber() external view returns (uint256) {
return number;
}
function version() external pure returns (uint256) {
return 2;
}
function _authorizeUpgrade(address newImplementation) internal override {}
} Proxy contract: // SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Proxy.sol)
pragma solidity ^0.8.20;
import {Proxy} from "../Proxy.sol";
import {ERC1967Utils} from "./ERC1967Utils.sol";
/**
* @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
* implementation address that can be changed. This address is stored in storage in the location specified by
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
* implementation behind the proxy.
*/
contract ERC1967Proxy is Proxy {
/**
* @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation`.
*
* If `_data` is nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
* encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
*
* Requirements:
*
* - If `data` is empty, `msg.value` must be zero.
*/
constructor(address implementation, bytes memory _data) payable {
ERC1967Utils.upgradeToAndCall(implementation, _data);
}
/**
* @dev Returns the current implementation address.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
*/
function _implementation() internal view virtual override returns (address) {
return ERC1967Utils.getImplementation();
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @aminsammara, So I went ahead and wrote the contracts myself on ![]() Why don't you consider testing stuff locally on your |
Beta Was this translation helpful? Give feedback.
Hello @aminsammara, So I went ahead and wrote the contracts myself on
remix
to see if things would play out differently for me, but it was the same for me, too,remix
is not showing the output of my function call. I think this is an issue ofremix
and not our process or contracts because the calls were successful.Why don't you consider testing stuff locally on your
vscode
usingFoundry
? That way, you would have more flexibility as you can useconsole
to show values. That is how I do it personally.