Persist OpenZeppelin CLI deployment on local blockchain (ganache-cli --db)?


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:

npx ganache-cli -d --db home/user/Documents/Openzepp1/Openzeppelin1_git/Ganache_Data

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.

1 Like

Hi @tschilpi,

I haven’t used the --db option 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)

Dear @frangio and @abcoathup

It worked :slight_smile: Specifying a network ID -i everytime I started the blockchain made it persist my deployments.

Thanks for the help!


Awesome! Would you like to report this to Ganache or should we do it?


Thanks @frangio,

I had tried setting the network ID on ganache-cli and on the OpenZeppelin CLI, when I only needed to set on ganache-cli.


I have posted in Truffles Gitter asking if this is intended behavior or whether to create an issue.


@frangio Let’s see what they respond to @abcoathup :slight_smile: Thank you!

1 Like

Hi @tschilpi,

I have logged as an Issue on the ganache-cli repository: