Set up your development environment
Get everything you need to start developing using the developer guides.
All of the developer guides assume that you are using a TypeScript development environment with a project structure similar to the one described here. You can follow the instructions in this section to prepare a development environment for working with the sample scripts in the Cozy developer guide repository.

Before you begin

Before you set up the development environment for creating protection markets, verify the following:
  • You have an internet connection and access to a shell terminal.
  • You have node.js and yarn installed.
  • You can connect to a node running locally or through a service such as Infura.
  • You have access to a wallet—including its private key—and can send transactions.

Prepare the development environment

To set up the development environment:
  1. 1.
    Clone the Cozy Developer Guides repository by running the following command:
    git clone [email protected]:Cozy-Finance/cozy-developer-guides.git
  2. 2.
    Install package dependencies by running the following command:
  3. 3.
    Create an environment file called .env to store information for connecting to the node provider and wallet.
    For example, if you are using the infura API and connecting to the Rinkeby test network, your .env file should look similar to the following example:
    Be careful to never commit these secrets to a repository!
  4. 4.
    Test your local environment by running the following command:
    yarn test
    If your development environment is ready to use, you should see output similar to the following to indicate that tests have passed:
    Creating Typechain artifacts in directory typechain for target ethers-v5
    Successfully generated Typechain artifacts!
    ✓ initializes properly (52ms)
    ✓ should not deploy if market is already triggered (424ms)
    ✓ does nothing when it should do nothing
    ✓ toggles trigger when expected to toggle trigger (58ms)
    ✓ returns a boolean with the value of isTriggered (446ms)
    5 passing (7s)

What's next?

The settings in the .env file are used to initialize the wallet and send transactions when the TypeScript files such as create-protection-market.ts are executed.
For example:
// Hardhat and ethers imports
import hre from 'hardhat';
import '@nomiclabs/hardhat-ethers';
import { Contract, ContractFactory } from 'ethers';
// Import some helper methods we have
import { getChainId, getContractAddress, logSuccess, logFailure, findLog, fundAccount } from '../utils/utils';
// Import any required ABIs
import comptrollerAbi from '../abi/Comptroller.json';
// Use the default Hardhat provider
const provider = hre.ethers.provider;
// Initialize our signer using the private key from the environment variable
const signer = new hre.ethers.Wallet(process.env.PRIVATE_KEY as string, hre.ethers.provider);
// Chain ID is used to determine which contract addresses to use, and we use a
// special helper method for getting chain ID. Normally you would get this from
// (await ethers.provider.getNetwork()).chainId, but since we are testing against
// a forked network we need to ensure we used the forked network's ID (e.g. 1 for
// mainnet) instead of the Hardhat default Chain ID of 1337
const chainId = getChainId(hre);
To finish setting up the development environment, you need to obtain the contract addresses and ABIs. You can find all of the contract addresses on the Contract deployments page. If you cloned the Cozy Developer Guides repository, you'll already have the ABIs. If you did not clone the repository, the contracts are verified on Etherscan, so you can get the ABIs from there [NOTE: currently not true].
Copy link
Before you begin
Prepare the development environment
What's next?