-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
We should offer some functionality to preserve deployments' information between Buidler executions.
One possible solution is to create a plugin that extends the Buidler Runtime Environment with an object containing (at least) these two methods:
-
getDeployedContracts: Receives a TruffleContract and returns an array of contract instances. This method should warn if the deployed contract's bytecode doesn't match the local's one. -
saveDeployedContract: Receives a contract instance, and saves its address. This method should warn if the contract was deployed to a testing/temporal network.
Under the hood, these methods should work with a JSON file looking something like this:
interface DeploymentsFile {
[chainId: number]: {
[contractName:string]: string[] // the addresses
}
}Any operation involving reading & updating that file has to be synchronous, and, if possible, atomic.
Once we have this plugin, deployment scripts could be written in this fashion:
let [token] = await deployments.getDeployedContracts(Token);
if (token === undefined) {
token = await Token.new();
await deployments.saveDeployedContract(token);
}
let [other] = await deployments.getDeployedContracts(Other);
if (other === undefined) {
other = await Other.new(123, token.address);
await deployments.saveDeployedContract(other);
}Writing them this way has the advantage of the scripts being resumable. If, for example, deploying Other fails because 123 wasn't a valid parameter, you can correct it and re-run the script without having to re-deploy the Token`.
Finally, other things that we should consider:
- We should also have some methods to "forget" about a certain contract.
- Should we store the deployment parameters?