Set Up Your Local Environment
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
- Foundry development framework for Ethereum:
curl -L https://foundry.paradigm.xyz | bash
# Reopen shell
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
npm init -y
Now install the following dependencies:
# To create Solidity smart contracts
# Install NPM package with strat library
npm install --save @mangrovedao/mangrove-core@latest
# Prepare Foundry's forge
forge init --force
# Set up remappings to use the strat library
" > remappings.txt
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.
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)
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 --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.
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.g.alchemy.com/v2/demo # Demo RPC provided by alchemy
export LOCAL_URL=http://127.0.0.1:8545 # Url for the local chan that anvil starts