I am writing a toy example of UUPS upgrade using the ERC1977Proxy. I am unable to understand how do I pass the initdata to the contract.
```
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
contract BoxV1 is UUPSUpgradeable {
address internal owner;
uint256 internal length;
uint256 internal width;
uint256 internal height;
function initialize(uint256 l, uint256 w, uint256 h) public initializer {
owner = msg.sender;
length = l;
width = w;
height = h;
}
function volume() public returns (uint256) {
return length * width * height;
}
function _authorizeUpgrade(address newImplementation) internal override virtual {
require(msg.sender == owner, "Unauthorized Upgrade");
}
And my proxy is defined as
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
contract BoxProxy is ERC1967Proxy {
constructor (address _delegate, bytes memory _data ) ERC1967Proxy(_delegate, _data) {
}
function getImplementation() public returns (address) {
return _getImplementation();
}
function upgradeTo(address newImplementation) public {
_upgradeTo(newImplementation);
}
}
What I want to achieve is something like below
box = await BoxV1.new();
const proxy1 = await BoxProxy.new(box.address, Buffer.from(""));
In the Buffer.from()
I think I have to pass the values of l
, w
, h
but I cant seem to find a way. I tried with Buffer.from([l, w, h])
and Buffer.from(l, w, h)
but they all seem to be throwihg exceptions.
I think I may not have a full understanding here, so please bear with me, and help me out.
My env from package.json looks like
dependencies": {
"@openzeppelin/contracts": "^4.1.0-rc.0",
"@openzeppelin/contracts-upgradeable": "^4.1.0-rc.0",
"@truffle/compile-solidity": "^5.2.6",
"dotenv": "^8.2.0"
},
"engines": {
"node": "16.0.x",
"npm": "7.10.x"
},