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.
Foundry development framework for Ethereum:
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:
Install dependencies
Now install the following dependencies:
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.
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.
How to fork an existing chain
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.
Tip :
The demo RPC URLs are unstable, so if you cannot connect then create your own or use a different one.
Last updated