Lockup vs Flow docs

Created Diff never expires
40 removals
Words removed56
Total words855
Words removed (%)6.55
177 lines
37 additions
Words added36
Total words835
Words added (%)4.31
175 lines
---
---
id: "local-environment"
id: "local-environment"
sidebar_position: 1
sidebar_position: 1
title: "Configure Your Local Environment"
title: "Configure Your Local Environment"
---
---


In this guide, we will go through the steps to set up a local development environment for building onchain integrations
In this guide, we will go through the steps to set up a local development environment for building onchain integrations
with Lockup. We will use Foundry to install Lockup as a dependency, and run a few simple tests.
with Flow. We will use Foundry to install Flow as a dependency, and run a few simple tests.


At the end, you’ll have a development environment set up that you can use to build the rest of the examples under
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.
"Guides", or start your own integration project.


## Pre-requisites
## Pre-requisites


You will need the following software on your machine:
You will need the following software on your machine:


- [Git](https://git-scm.com/downloads)
- [Git](https://git-scm.com/downloads)
- [Foundry](https://github.com/foundry-rs/foundry)
- [Foundry](https://github.com/foundry-rs/foundry)
- [Node.js](https://nodejs.org/en/download)
- [Node.js](https://nodejs.org/en/download)
- [Bun](https://bun.sh)
- [Bun](https://bun.sh)


In addition, familiarity with [Ethereum](https://ethereum.org/) and [Solidity](https://soliditylang.org/) is requisite.
In addition, familiarity with [Ethereum](https://ethereum.org/) and [Solidity](https://soliditylang.org/) is requisite.


## Set up using Lockup integration template
## Set up using Flow integration template


We put together a template repository that you can use to get started quickly. This repository features a basic project
We put together a template repository that you can use to get started quickly. This repository features a basic project
structure, pre-configured Lockup imports, and a selection of sample contracts and tests.
structure, pre-configured Flow imports, and a selection of sample contracts and tests.


:::tip
:::tip


Make sure you are using the latest version of Foundry by running `foundryup`.
Make sure you are using the latest version of Foundry by running `foundryup`.


:::
:::


To install the template, simply execute the following commands:
To install the template, simply execute the following commands:


```shell
```shell
$ mkdir lockup-integration-template
$ mkdir flow-integration-template
$ cd lockup-integration-template
$ cd flow-integration-template
$ forge init --template sablier-labs/lockup-integration-template
$ forge init --template sablier-labs/flow-integration-template
$ bun install
$ bun install
```
```


Then, hop to the [Run a Fork Test](/guides/lockup/examples/local-environment#run-a-fork-test) section to complete your
Then, hop to the [Run a Fork Test](/guides/flow/examples/local-environment#run-a-fork-test) section to complete your set
set up and start developing.
up and start developing.


## Set up using Foundry template
## Set up using Foundry template


Foundry is a popular development toolkit for Ethereum projects, which we have used to build the Sablier Protocols. For
Foundry is a popular development toolkit for Ethereum projects, which we have used to build the Sablier Protocols. For
the purposes of this guide, Foundry will provide us with the tooling needed to compile and test our contracts.
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:
Let's use this command to spin up a new Foundry project:


```shell
```shell
$ forge init my-project
$ forge init my-project
$ cd my-project
$ cd my-project
```
```


:::note
:::note


You might notice that the CLI is `forge` rather than `foundry`. This is because Foundry is a toolkit, and `forge` is
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.
just one of the tools that comes with it.


:::
:::


Once the initialization completes, take a look around at what got set up:
Once the initialization completes, take a look around at what got set up:


```tree
```tree
├── foundry.toml
├── foundry.toml
├── script
├── script
├── src
├── src
└── test
└── test
```
```


The folder structure should be intuitive:
The folder structure should be intuitive:


- `src` is where you'll write Solidity contracts
- `src` is where you'll write Solidity contracts
- `test` is where you'll write tests (also in Solidity)
- `test` 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)
- `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
- `foundry.toml` is where you can configure your Foundry settings, which we will leave as is in this guide


## Install Lockup npm packages
## Install Flow npm package


Let's install the Lockup Node.js packages using Bun:
Let's install the Flow Node.js packages using Bun:


```shell
```shell
$ bun add @sablier/v2-core @sablier/v2-periphery
$ bun add @sablier/flow
```
```


Bun will download the Lockup contracts, along with their dependencies, and put them in the `node_modules` directory.
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
Let's remap the package names to point to the installed contracts. This step is required so that the Solidity compiler
can find the Lockup contracts when you import them:
can find the Flow contracts when you import them:


```shell
```shell
$ echo "@sablier/v2-core=node_modules/@sablier/v2-core/" >> remappings.txt
$ echo "@sablier/flow=node_modules/@sablier/flow/" >> remappings.txt
$ echo "@sablier/v2-periphery=node_modules/@sablier/v2-periphery/" >> remappings.txt
$ echo "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/" >> remappings.txt
$ echo "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/" >> remappings.txt
$ echo "@prb/math/=node_modules/@prb/math/" >> 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 Lockup integrations. Let's
That's it! You should now have a functional development environment to start building onchain Flow integrations. Let's
run a quick test to confirm everything is set up properly.
run a quick test to confirm everything is set up properly.


## Write your first contract
## Write your first contract


Delete the `src/Counter.sol` and `test/Counter.t.sol` files generated by Forge, and create two new files:
Delete the `src/Counter.sol` and `test/Counter.t.sol` files generated by Forge, and create a new file:
`src/StreamCreator.sol` and `test/StreamCreator.t.sol`.
`src/FlowStreamCreator.sol`.


Paste the following code into `src/StreamCreator.sol` (a detailed explanation of this contract can be found
Paste the following code into `src/FlowStreamCreator.sol`.
[here](/guides/lockup/examples/create-stream/lockup-linear)):


```solidity reference title="Lockup Linear Stream Creator"
```solidity reference title="Flow Stream Creator"
https://github.com/sablier-labs/examples/blob/main/lockup/core/LockupLinearStreamCreator.sol
https://github.com/sablier-labs/flow-integration-template/blob/main/src/FlowStreamCreator.sol
```
```


Let's use Forge to compile this contract:
Let's use Forge to compile this contract:


```shell
```shell
$ forge build
$ forge build
```
```


If the contract was compiled correctly, you should see this message:
If the contract was compiled correctly, you should see this message:


```text
```text
[⠢] Compiling...
[⠢] Compiling...
[⠰] Compiling { number } files with { compiler }
[⠰] Compiling { number } files with { compiler }
[⠒] Solc { compiler } finished in { time }
[⠒] Solc { compiler } finished in { time }
Compiler run successful
Compiler run successful
```
```


:::info
:::info


The minimum Solidity version supported by the Lockup contracts is v0.8.13.
The minimum Solidity version supported by the Flow contracts is v0.8.22.


:::
:::


## Run a fork test
## Run a fork test


Foundry offers native support for running tests against a fork of Ethereum Mainnet, testnets and L2s, which is useful
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
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.
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
As a prerequisite, you will need an RPC that supports forking. A good solution for this is
[Alchemy](https://alchemy.com/), as it includes forking in its free tier plan.
[Alchemy](https://alchemy.com/), as it includes forking in its free tier plan.


Once you have obtained your RPC, you can proceed to run the following test:
Once you have obtained your RPC, you can proceed to run the following test:


```solidity reference title="Stream Creator Test"
```solidity reference title="Stream Creator Test"
https://github.com/sablier-labs/examples/blob/main/lockup/core/LockupStreamCreator.t.sol
https://github.com/sablier-labs/flow-integration-template/blob/main/test/FlowStreamCreator.t.sol
```
```


You can run the test using Forge:
You can run the test using Forge:


```shell
```shell
$ forge test
$ forge test
```
```


If the test passed, you should see a message like this:
If the test passed, you should see a message like this:


```text
```text
Ran 2 tests for lockup/core/LockupStreamCreator.t.sol:LockupStreamCreatorTest
Ran 2 tests for test/FlowStreamCreator.t.sol:FlowStreamCreatorTest
[PASS] test_LockupDynamicStreamCreator() (gas: 273719)
[PASS] test_CreateFlowStream() (gas: 147915)
[PASS] test_LockupLinearStreamCreator() (gas: 186388)
[PASS] test_CreateFlowStreamAndDeposit() (gas: 224823)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 6.34s (5.80s CPU time)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 986.20ms (4.16ms CPU time)
```
```


## Next steps
## Next steps


Congratulations! Your environment is now configured, and you are prepared to start building. Explore the guides section
Congratulations! Your environment is now configured, and you are prepared to start building. Explore the guides section
to discover various Lockup features available for integration. Remember to include all contracts (`.sol` files) in the
to discover various Flow features available for integration. Remember to include all contracts (`.sol` files) in
`src` folder and their corresponding tests in the `test` folder.
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
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](https://book.getfoundry.sh/), which contains numerous examples and tutorials. A deep understanding of
[Foundry Book](https://book.getfoundry.sh/), which contains numerous examples and tutorials. A deep understanding of
Foundry will enable you to create more sophisticated integrations with Lockup.
Foundry will enable you to create more sophisticated integrations with Flow.