Deploying Smart Contracts
A hitchhikers guide to deploying smart contracts for the Index Coop
Deploying a smart contract for the Coop is generally done according to the following process:
cp .env.default .env
Now you'll want to replace some of the variables in your
Once you have that key, replace
.envwith your new API key.
Once created, you'll see a Project ID on the overview page. Copy that ID and set it as the value of
Finally, replace the
KOVAN_DEPLOY_PRIVATE_KEYwith your wallet's private key. If you're nervous about this, then create a new wallet in MetaMask with nothing in it, and use that private key to avoid mixing your actual wallet.
In a terminal window, run
yarn create:deployment my_contract_name
my_contract_nameis the name of your contract deployment, for example:
yarn create:deployment btcfli_rebalance_viewer
New deployment files at:
This will create 3 files with the appropriate migration number. Respectively, these are the deployment script, the deployment constants, and deployment tests. Populate these similarly to the other files that precede them.
In a terminal, run
In another terminal, run
This will run all the unit tests you've written, and verify that everything is built out like you expect it to be. From here, you can also run
This will deploy your contract to your locally running blockchain from
yarn chainand make sure the deployment goes smoothly before you deploy to Kovan.
Remember that wallet private keys you used to replace the
KOVAN_DEPLOY_PRIVATE_KEYdefault value? That wallet will need some ETH to deploy the contract to the testnet. You can find a faucet from myCrypto here that can send you some Kovan ETH.
Once you've secured your Kovan ETH run the following commands in a terminal:
After everything is finished running, you should receive an Etherscan URL and a contract address that will lead you to your contract! If your deployment actually deployed multiple contracts, you should get URLs and addresses for each as they're deployed.
If you’ve passed all tests, and all boxes are ticked, submit a PR. Some CI tests will run once the PR is published, so keep an eye out for those. If any issues arise, they’ll need to be addressed before being able to be reviewed and merged.