Pre-deploying contracts to testnets
Explanation of the pre_built_artifacts
Normally when building the application against a local development network we deploy the contracts at compile time. However when targeting a test network this isn't very practical as deployment takes a long time.
To speed up the developer workflow, we have deployed the contracts in advance to the following test networks using truffle:
Ropsten
Kovan
Rinkeby
The truffle artifacts created from the deployments are located here:
/contracts/pre_built_artifacts/
When the TARGET_NETWORK
environment variable is set to a test network, webpack will use the predeployed artifacts instead of trying to deploy the contracts at compile time:
If we are targeting a development network, this snippet will use the artifacts that truffle just created at compile time. Otherwise it replaces all references to /build/contracts/*.json
files to the predeployed artifacts in /contract/pre_built_artifacts
folder.
Deploying Contracts to a Test Network
There's a few steps to follow to deploy and create the pre-deployed artifacts:
Delete the
/build/contract
folder. This removes any existing artifacts that might be there and contain references to development network.Set
TARGET_NETWORK
in your.env
file to your desired test network.Run
yarn deployContracts
Repeat step 2 and 3 for any other test networks you want to pre deploy to.
Copy the
.json
files from/build/contracts
to the/contract/pre_built_artifacts
folder.Remove unecessary fields from these
.json
files: we only needabi
,bytecode
andnetworks.
Check in the updated artifacts to source control.
Last updated