I am trying to set up a ProxyAdmin project using the SDK (rather than CLI) as i have requirements i cannot meet with the CLI. The “usage” documentation on the projects GIT simply do not work correctly.
ZWeb3.initialize(web3.currentProvider);
this.project = new ProxyAdminProject('MyProject', { from: await ZWeb3.defaultAccount(), gas: 1e6, gasPrice: 1e9 });
gives the error
"Contract or address expected"
after looking through the upgrades code i see the constructor takes 4 params so i try this
ZWeb3.initialize(web3.currentProvider);
this.project = new ProxyAdminProject('MyProject', null, null, { from: await ZWeb3.defaultAccount(), gas: 1e6, gasPrice: 1e9 });
const GeneralUserV0 = Contracts.getFromLocal('GeneralUser');
const instance1 = await this.project.createProxy(GeneralUserV0);
const instance2 = await this.project.createProxy(GeneralUserV0);
const GeneralUserV2 = Contracts.getFromLocal('GeneralUserV2')
await this.project.upgradeProxy(this.contractAddressUser1, GeneralUserV2)
at this point the createProxy contracts deploy properly (i tested calling the contracts using web3) however when i try to upgrade the contracts i get “out of gas” which i find odd (unsure how the contracts got deployed when the admin account has 0 eth, please read on for explanation)
So i then check the “Proxy Admin” address to find out it is null
ZWeb3.initialize(web3.currentProvider);
this.project = new ProxyAdminProject('MyProject', null, null, { from: await ZWeb3.defaultAccount(), gas: 1e6, gasPrice: 1e9 });
this.progjectAdminAddress = await this.project.getAdminAddress()
console.log("ADMIN: ", this.progjectAdminAddress); <<< NNULL
// Create proxxy contracts for users
const GeneralUserV0 = Contracts.getFromLocal('GeneralUser');
const instance1 = await this.project.createProxy(GeneralUserV0);
const instance2 = await this.project.createProxy(GeneralUserV0);
const GeneralUserV2 = Contracts.getFromLocal('GeneralUserV2')
await this.project.upgradeProxy(this.contractAddressUser1, GeneralUserV2)
so i then use the “ensure admin function”
ZWeb3.initialize(web3.currentProvider);
this.project = new ProxyAdminProject('MyProject', null, null, { from: await ZWeb3.defaultAccount(), gas: 1e6, gasPrice: 1e9 });
await this.project.ensureProxyAdmin()
this.progjectAdminAddress = await this.project.getAdminAddress()
// Create proxxy contracts for users
const GeneralUserV0 = Contracts.getFromLocal('GeneralUser');
const instance1 = await this.project.createProxy(GeneralUserV0);
const instance2 = await this.project.createProxy(GeneralUserV0);
const GeneralUserV2 = Contracts.getFromLocal('GeneralUserV2')
await this.project.upgradeProxy(this.contractAddressUser1, GeneralUserV2)
Which now gives me a proxy admin address but also gives a balance of 0 so again i obviously get “out of gas”
What is the propper way to set up a project? looking at the constructor of ProxyAdminProject i guess i have to manually instantiate an instance ProxyAdmin class and pass it into ProxyAdminProject contractor. is this correct?
I see on the GIT the API is a TODO is there anywhere i can get some sort of API documentation even if it is half baked.
EDIT: update
I forgot to metion i have also tried allocating ETH to an account and using that account as the admin also (I am passing in a full private key have just ommited for posting here, even though it isnt a key in use)
const startBlockchainServer = (port, opts) => (
new Promise((resolve, reject) => {
const server = ganache.server(opts);
server.listen(port, function(err, blockchain) {
console.log(err)
if(err) reject(err);
resolve(blockchain)
});
}))
await startBlockchainServer(BLOCKCHAIN_PORT, {
accounts: [
{ secretKey: "0xcce0c867c6722a02f98b482cd9bd94106eaf56fb3c2dd666ff...", balance: 10000000000000000000 }
]
});
admin = await web3.eth.accounts.privateKeyToAccount("0xcce0c867c6722a02f98b482cd9bd94106eaf56fb3c2dd666ff...");
ZWeb3.eth.accounts.wallet.add(admin)
const project = new ProxyAdminProject('MyProject', null, null, { from: admin.address, gas: 1e6, gasPrice: 1e9 });
const GeneralUserV2 = Contracts.getFromLocal('GeneralUserV2')
project.upgradeProxy(this.contractAddressUser1, GeneralUserV2)
When i check the balance of the “admin” wallet i created i can see the amount of ETH has decreased after creating an instance of ProxyAdminProject
however when i try to upgrade i still get VM Exception while processing transaction: out of gas
Thanks for the help
Environment
@openzeppelin/upgrades v2.8.0
ganache-cli v6.9.1
mocha to run tests
Details
I understand why am getting the errors i am, it’s more there is no clear was to set up a project and preform upgrades. The code in the docs simply do not work and seem out of date as the constructor takes more params than the example shows. and this class will not work without those extra params it seems.
Code to reproduce
Minimal example taken from much lager code base
const { Contracts, ProxyAdminProject, ZWeb3, ProxyAdmin, Transactions } = require('@openzeppelin/upgrades');
const ganache = require("ganache-cli");
const BLOCKCHAIN_PORT = '8545'
const startBlockchainServer = (port, opts) => (
new Promise((resolve, reject) => {
const server = ganache.server();
server.listen(port, function(err, blockchain) {
console.log(err)
if(err) reject(err);
resolve(blockchain)
});
}))
describe('Test', function () {
this.accounts;
this.project;
this.progjectAdminAddress;
this.user1Contarct;
this.user2Contract;
this.web3User1ContractInstance;
this.web3User2ContractInstance;
this.user1EthAccount;
this.user2EthAccount;
this.contractAddressUser1;
it.only('Deploy User smart contracts', async function(){
await startBlockchainServer(BLOCKCHAIN_PORT, {});
ZWeb3.initialize(web3.currentProvider);
this.project = new ProxyAdminProject('MyProject', null, null, { from: await ZWeb3.defaultAccount(), gas: 1e6, gasPrice: 1e9 }).createProxy();
// Get Admin address
await this.project.ensureProxyAdmin()
this.progjectAdminAddress = await this.project.getAdminAddress()
// Create proxxy contracts for users
const GeneralUserV0 = Contracts.getFromLocal('GeneralUser');
const instance1 = await this.project.createProxy(GeneralUserV0);
const instance2 = await this.project.createProxy(GeneralUserV0);
const GeneralUserV2 = Contracts.getFromLocal('GeneralUserV2')
await this.project.upgradeProxy(this.instance1.address, GeneralUserV2)
})
})