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:
    1
    git clone [email protected]:Cozy-Finance/cozy-developer-guides.git
    Copied!
  2. 2.
    Install package dependencies by running the following command:
    1
    yarn
    Copied!
  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:
    1
    RPC_URL=https://rinkeby.infura.io/v3/yourInfuraId
    2
    PRIVATE_KEY=0xYourPrivateKey
    Copied!
    Be careful to never commit these secrets to a repository!
  4. 4.
    Test your local environment by running the following command:
    1
    yarn test
    Copied!
    If your development environment is ready to use, you should see output similar to the following to indicate that tests have passed:
    1
    Creating Typechain artifacts in directory typechain for target ethers-v5
    2
    Successfully generated Typechain artifacts!
    3
    4
    MockTrigger
    5
    Deployment
    6
    ✓ initializes properly (52ms)
    7
    ✓ should not deploy if market is already triggered (424ms)
    8
    checkAndToggleTrigger
    9
    ✓ does nothing when it should do nothing
    10
    ✓ toggles trigger when expected to toggle trigger (58ms)
    11
    ✓ returns a boolean with the value of isTriggered (446ms)
    12
    5 passing (7s)
    Copied!

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:
1
// Hardhat and ethers imports
2
import hre from 'hardhat';
3
import '@nomiclabs/hardhat-ethers';
4
import { Contract, ContractFactory } from 'ethers';
5
6
// Import some helper methods we have
7
import { getChainId, getContractAddress, logSuccess, logFailure, findLog, fundAccount } from '../utils/utils';
8
9
// Import any required ABIs
10
import comptrollerAbi from '../abi/Comptroller.json';
11
12
// STEP 0: ENVIRONMENT SETUP
13
// Use the default Hardhat provider
14
const provider = hre.ethers.provider;
15
16
// Initialize our signer using the private key from the environment variable
17
const signer = new hre.ethers.Wallet(process.env.PRIVATE_KEY as string, hre.ethers.provider);
18
19
// Chain ID is used to determine which contract addresses to use, and we use a
20
// special helper method for getting chain ID. Normally you would get this from
21
// (await ethers.provider.getNetwork()).chainId, but since we are testing against
22
// a forked network we need to ensure we used the forked network's ID (e.g. 1 for
23
// mainnet) instead of the Hardhat default Chain ID of 1337
24
const chainId = getChainId(hre);
Copied!
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].
Last modified 2mo ago