I’m trying to follow this https://github.com/OpenZeppelin/openzeppelin-sdk/blob/master/examples/upgrades-library
to make my contract programatically upgradable.
Firstly, I wanted to deploy it in one script and then upgrade it with some changes made in another script. I wrote the deploy.js script like this:
const Web3 = require('web3');
const { Contracts, ProxyAdminProject, ZWeb3 }=require('@openzeppelin/upgrades');
async function main(web3) {
// Create web3 provider and initialize OpenZeppelin upgrades
if (!web3) web3 = new Web3('http://localhost:8545');
ZWeb3.initialize(web3.currentProvider)
// Create an OpenZeppelin project
const [from] = await ZWeb3.eth.getAccounts();
const project = new ProxyAdminProject('MyProject', null, null, { from, gas: 1e6, gasPrice: 1e9 });
// Deploy an instance of MyContractV0
console.log('Creating an upgradeable instance of v1...');
const SimpleStorageV1 = Contracts.getFromLocal('SimpleStorageV1');
const instance = await project.createProxy(SimpleStorageV1, {initArgs: [0]});
const address = instance.options.address;
console.log(`Contract created at ${address}`);
}
main();
but what I’ve been unable to understand is where does it get the contracts from via Contracts.getFromLocal?
I assumed it was from the build directory so I went on to run $ npx oz compile where it began to throw the error shown below:
$ npx oz compile
/media/asmee/Presentations/upgradeProgrammatically/build/contracts/Initializable.json: Unexpected end of JSON input
And I checked that the build directory contains bothe initializable.json and SimpleStorageV1.json but both are empty!
Can you please guide me on this?
Here’s by SimpleStorageV1.sol file:
//"SPDX-License-Identifier: UNLICENSED"
pragma solidity ^0.6.0;
import "@openzeppelin/upgrades/contracts/Initializable.sol";
contract SimpleStorage is Initializable {
uint256 storedValue;
function initialize (uint256 _initialValue) public initializer {
storedValue = _initialValue;
}
function retrieve() public view returns (uint256){
return storedValue;
}
}