Configure Your Local Environment
At the end, you’ll have a development environment set up that you can use to build the rest of the examples under "Guides", or start your own integration project.
Pre-requisites
You will need the following software on your machine:In addition, familiarity with Ethereum and Solidity is requisite.
Set up using Flow integration template
tip
Make sure you are using the latest version of Foundry by running foundryup
.
To install the template, simply execute the following commands:
$ mkdir flow-integration-template
$ cd flow-integration-template
$ forge init --template sablier-labs/flow-integration-template
$ bun install
Then, hop to the Run a Fork Test section to complete your set up and start developing.
Set up using Foundry template
Foundry is a popular development toolkit for Ethereum projects, which we have used to build the Flow Protocol. For the purposes of this guide, Foundry will provide us with the tooling needed to compile and test our contracts.Let's use this command to spin up a new Foundry project:
$ forge init my-project
$ cd my-project
Once the initialization completes, take a look around at what got set up:├── foundry.toml
├── script
├── src
└── test
The folder structure should be intuitive:src
is where you'll write Solidity contractstest
is where you'll write tests (also in Solidity)script
is where you'll write scripts to perform actions like deploying contracts (you guessed it, in Solidity)foundry.toml
is where you can configure your Foundry settings, which we will leave as is in this guide
note
You might notice that the CLI is forge
rather than foundry
. This is because Foundry is a toolkit, and forge
is
just one of the tools that comes with it.
Install Flow npm package
Let's install the Flow Node.js packages using Bun:$ bun add @sablier/flow
Bun will download the Flow contracts, along with their dependencies, and put them in the node_modules
directory.Let's remap the package names to point to the installed contracts. This step is required so that the Solidity compiler can find the Flow contracts when you import them:
$ echo "@sablier/flow=node_modules/@sablier/flow/" >> remappings.txt
$ echo "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/" >> remappings.txt
$ echo "@prb/math/=node_modules/@prb/math/" >> remappings.txt
That's it! You should now have a functional development environment to start building onchain Flowintegrations. Let's run a quick test to confirm everything is set up properly.
Write your first contract
Delete thesrc/Counter.sol
and test/Counter.t.sol
files generated by Forge, and create two new files:src/StreamCreator.sol
and test/StreamCreator.t.sol
.Paste the following code into
src/StreamCreator.sol
:Flow Stream Creator
loading...
$ forge build
If the contract was compiled correctly, you should see this message:[⠢] Compiling...
[⠰] Compiling 62 files with Solc 0.8.26
[⠒] Solc 0.8.26 finished in 967.04ms
Compiler run successful!
info
The minimum Solidity version supported by the Flow contracts is v0.8.22.
Run a fork test
Foundry offers native support for running tests against a fork of Ethereum Mainnet, testnets and L2s, which is useful when building and testing integrations with onchain protocols like Sablier. In practice, this enables you to access all Sablier contracts deployed on Ethereum, and use them for testing your integration.As a prerequisite, you will need an RPC that supports forking. A good solution for this is Alchemy, as it includes forking in its free tier plan.
Once you have obtained your RPC, you can proceed to run the following test:
Flow Stream Creator Test
loading...
$ forge test
If the test passed, you should see a message like this:Ran 2 tests for test/FlowStreamCreator.t.sol:FlowStreamCreatorTest
[PASS] test_CreateFlowStream() (gas: 246830)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 626.58ms (500.67µs CPU time)
Next steps
Congratulations! Your environment is now configured, and you are prepared to start building. Explore the guides section to discover various features available for Flow integration. Remember to include all contracts (.sol
files) in the src
folder and their corresponding tests in the test
folder.As far as Foundry is concerned, there is much more to uncover. If you want to learn more about it, check out the Foundry Book, which contains numerous examples and tutorials. A deep understanding of Foundry will enable you to create more sophisticated integrations with Flow protocol.