Setup of the development environment

Prerequisites

  1. A running Docker instance (or other compatible container engine)

  2. Visual Studio Code (VS Code) with the Remote Development Extension Pack installed

  3. Know how to work with devcontainers (optional)

Installing Docker on Windows is sometimes a struggle. Recommended Approach: Follow the installation instructions for Docker Desktop. Installing Docker on Linux or Mac should be straight forward.

Get the source code and editor ready

  1. Fork the gif-sandbox repository to your own github account (if you want to be able to commit changes)

  2. Clone the repository to your local machine

  3. Open the repository in VS Code

There are three ways to work with the sandbox (described below)

  • Use the devcontainer provided in the repository

  • Use Github Codespaces

  • Run the brownie container outside of vscode devcontainer

Start the sandbox devcontainer

  • Start the devcontainer (either wait for the pop to build the devcontainer or open the command list (F1) and select the command Dev Containers: Rebuild and reopen in container)

  • Wait for the devcontainer to finish compiling and deploying the contracts

  • The devcontainer setup includes a second container with a ganache instance that is started automatically. A GIF instance is deployed to this ganache instance and the address of the GIF instance is stored in the file gif_instance_address.txt in the project root. This GIF instance can also be used by other (newly developed) products/riskpools/oracles for testing purposes.

Use Github Codespaces

Github Codespaces is a new feature of Github that allows you to work with a repository in a container environment hosted by Github. To use Github Codespaces you need to have a Github account and you need to be logged in to Github. Open the gif-sandbox repository in your browser and click on the button Code and select Open with Codespaces from the dropdown menu. This will open a new browser tab with the sandbox repository in a devcontainer hosted by Github. You can now work with the sandbox repository in the browser (or open the codespace in VS Code by clicking on the button Open with VS Code in the upper right corner of the browser tab).

To improve performance of the codespace you can change the machine type in the codespace settings.

Run brownie container outside of vscode devcontainer

Build the brownie container

docker build -t gif-sandbox-brownie -f Dockerfile.brownie-container .

Run the brownie container

docker run -v .:/sandbox -p 7545:7545 -p 8000:8000 --name gif-sandbox-brownie gif-sandbox-brownie

Open another terminal (the above command will block you current terminal) and start an interactive shell in the brownie container to execute commands

docker exec -it gif-sandbox-brownie bash

After that you need to add the ganache network to the brownie config once and create an empty .env file

brownie networks add Local ganache host=http://localhost:7545 chainid=1337
touch .env

When you are done with the brownie container you can exit the interactive shell (type exit) and stop the container

docker stop gif-sandbox-brownie
# to remove the container run
docker rm gif-sandbox-brownie

Reset devcontainer

To completely reset a devcontainer instance follow these steps

  1. Shutdown and remove the devcontainer and associated containers

  2. Remove the ganache-db volume from the devcontainers ganache instance

  3. Delete the file gif_instance_address.txt from the project sources

  4. Restart the devcontainer as described above in the section Start devcontainer