Set Up Your Local Environment
Local developmentβ
If you want to do any local development we recommend installing Node.js and Foundry. We are going to be using Node.js for package management and running javascript in the tutorials, but it is not required. You can use any development environment that supports javascript and npm packages.
We are going to be using Foundry to start local forks for existing chains. You don't have to use Foundry to do this, you can use any tool you want to do this, but we recommend Foundry.
For Linux or macOS everything should work out of the box, if you are using Windows, then we recommend installing everything from within WSL2 and expect some quirks. Remember to reopen your shell after running the first line.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# Reopen shell
nvm install --lts
# Enable the Yarn 2 package manager
corepack enable
- Foundry development framework for Ethereum:
curl -L https://foundry.paradigm.xyz | bash
# Reopen shell
foundryup
Create tutorial folderβ
The tutorials can be run in an isolated folder where you install Mangrove dependencies.
Open a terminal and run the following commands:
# Create a folder for the tutorial and enter it
mkdir tutorial
cd tutorial
npm init -y
Install dependenciesβ
Now install the following dependencies:
# To use the mangrove SDK
npm install --save dotenv
npm install --save @mangrovedao/mangrove.js@latest
Environmentβ
Inside the tutorial folder, create a .env
file. This will hold the secrets such as private key and API keys. Here we describe it in general, but the next section provides some working example values.
The file should typically look as follows (with <...>
replaced by proper values) - for instance you need a RPC URL from, e.g., Infura or Alchemy, and an EOA with a private key. Note, there are other ways to provide secrets, but this is what we do in the tutorials.
If you do not have a RPC URL, there exists free RPC URLs, some examples can be found here: ChainList - note that they can be unstable and in that case we recommend creating your own through the listed providers.
# .env
export PRIVATE_KEY=<private key> # 0xabcd.... <- This is the private key you'll be using in the tutorial - a test key for the Polygon Mumbai network
export ADMIN_ADDRESS=<EOA> # 0xabcd...
export RPC_URL=<https://polygon-mumbai.g.alchemy.com/v2/API key> # alchemy or infura node url for Polygon Mumbai
export LOCAL_URL=http://127.0.0.1:8545 # Url for the local chain that anvil starts (see next section)
Local chainβ
The tutorials can be run directly on networks where Mangrove is deployed (see Addresses). However on a real network you will spend real tokens, so we recommend starting on test networks with a test account.
To further speed things up we run tutorials on a local fork of a chain using Foundry's anvil
tool.
source .env
anvil --fork-url $RPC_URL
This starts a new chain on with a local url of http://127.0.0.1:8545
. You can read more about the anvil
command here, if you are interested.
When anvil
starts up, it creates 10 test accounts, with some native tokens. If you do not have a real account on the chain, you can always use these accounts. Here is an example of a .env
file that uses the first anvil account, a demo RPC URL and with a LOCAL URL.
The demo RPC URLs are unstable, so if you cannot connect then create your own or use a different one.
export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # The first anvil private key
export ADMIN_ADDRESS=0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 # The matching public key, to the first anvil private key
export RPC_URL=https://polygon-mumbai.blockpi.network/v1/rpc/public # Public RPC provided by Block Pi
export LOCAL_URL=http://127.0.0.1:8545 # Url for the local chan that anvil starts