I’ve been following the guide on the oz webpage for deploying contracts. It is stated that a local ganache blockchain does not persist it’s data throughout several runs. However, you can run ganache with the -db command and refer it to a directory where it can store and access data from:
I’ve restarted the ganache-cli and refered to it’s stored data in Ganache_Data with the --db command. Apparently the same Blockchain is used again (addresses are the same). However, the deployments apparently did not persist:
When I run npx oz call, it gives me choice of network name and then gives out a red line saying that I need to specify the contracts address:
A contract address must be specified.
I redeploy the Box.sol contract with npx oz deploy. Now I can call npx oz call again, and it gives me as a choice the same Box.sol contract address.
So apparently the deployment of the Box contract didn’t persist through my runs. Shouldn’t it have been stored in /Ganache_Data/? I refered my ganache-cli to that folder everytime I started it.
I haven’t used the --dboption of ganache-cli before.
It looks like when we restart ganache-cli then the OpenZeppelin CLI treats this as a new local blockchain, even though the state of the blockchain remains the same.
A new <network_name>.json is created by the OpenZeppelin CLI when ganache-cli is restarted.
Other than manually modifying the config, I am not sure if this is supported with the CLI currently.
I tried a couple of options (such as changing the network name in network.js, specifying the network on commands, specifying a network ID) but wasn’t able to get anything to work.
The issue is probably that a new process has a different network id even if it reuses the data. This sounds like a bug in Ganache that you should report to them (--db should also persist network id), but as a workaround you can try explicitly specifying a networkId using the CLI flag:
-i or --networkId : Specify the network id ganache-cli will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured)