Skip to main content

Quickstart

Superfluid is a protocol revolving around a new token standard called Super Token. Super Tokens have special capabilities (super powers?). One of them allows to create second-by-second token transfers (called Money Streaming). In this guide, we'll walk through the process of setting up and deploying a basic contract for creating, updating and deleting Superfluid money streams. Let's go!

Why this Quickstart?

This is just an example to get you started with Superfluid. You can use this as a base to build more complex applications.

You DO NOT need to set up the FlowSender contract to create, update and delete streams. You can do this directly from the Dashboard or by interacting with the CFAv1Forwarder contract.

Prerequisites

  • Solidity knowledge
  • A development environment (Remix, Hardhat, or Foundry)
  • A testnet wallet (e.g., MetaMask)
  • Access to a testnet native coin (e.g. Polygon Mumbai Testnet Matic - get faucet here)

Contract Overview: FlowSender

In this guide we will describe the contract FlowSender:

  • This contract is designed to interact with the Superfluid protocol, specifically to send Super Tokens using Money Streaming.
  • This contract enables the creation, modification, and deletion of continuous money streams.
  • The contract interacts with an example super token (fake DAI Super Token - fDAIx) to create a stream from itself to a receiver.
  • Each time a stream is created, a new receiver is added to the list of receivers, and the Superfluid Protocol keeps track of the balances and the receivers on the blockchain.

Visualization showing the user creating a flow through FlowSender and all of the streams that have been created

What is Tx?

If you are new to blockchain development, you may not be familiar with the term "Tx". Tx is short for transaction, which is a record of an action on the blockchain. Transactions are used to transfer value, store data, and interact with smart contracts.

Contract and Key Functions

Click here to show FlowSender contract

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ISuperfluid, ISuperToken } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";
import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";

interface IFakeDAI is IERC20 {
function mint(address account, uint256 amount) external;
}

contract FlowSender {
using SuperTokenV1Library for ISuperToken;

mapping (address => bool) public accountList;
ISuperToken public daix;

// fDAIx address on Polygon Mumbai = 0x5D8B4C2554aeB7e86F387B4d6c00Ac33499Ed01f
constructor(ISuperToken _daix) {
daix = _daix;
}

/// @dev Mints 10,000 fDAI to this contract and wraps it all into fDAIx
function gainDaiX() external {

// Get address of fDAI by getting underlying token address from DAIx token
IFakeDAI fdai = IFakeDAI( daix.getUnderlyingToken() );

// Mint 10,000 fDAI
fdai.mint(address(this), 10000e18);

// Approve fDAIx contract to spend fDAI
fdai.approve(address(daix), 20000e18);

// Wrap the fDAI into fDAIx
daix.upgrade(10000e18);
}

/// @dev controls a stream with the given flowrate between this contract and the desired receiver
function setStream(address receiver, int96 flowRate) external {
daix.flow(receiver, flowRate);
}

/// @dev get flow rate between this contract and the given receiver
function getFlowRate(address receiver) external view returns (int96 flowRate) {
return daix.getFlowRate(address(this), receiver);
}
}

  • gainDaiX: Mints and wraps fDAI into fDAIx (Superfluid's wrapped token).
  • setStream: Controls a stream between the contract and a receiver
  • getFlowRate: Reads the current flow rate of a stream.

Environment Setup and Deployment

Deploy the FlowSender contract to a testnet using your preferred development environment.

Using Remix IDE

  1. Access Remix IDE: Visit Remix IDE.
  2. Create New File: In the 'File Explorers' tab, create a new .sol file.
  3. Paste Contract Code: Copy the FlowSender contract code into the new file.
  4. Compile the Contract: Go to the 'Solidity Compiler' tab and click 'Compile'.
  5. Deploy the Contract:
    • Switch to the 'Deploy & Run Transactions' tab.
    • Connect to MetaMask, selecting Mumbai Testnet.
    • Click on 'Deploy' to deploy your contract.

For more information, check out the Remix IDE documentation.

What is the token address?

When deploying the contract, you will need to provide the address of the fDAIx token on the testnet you are using. You can find those addresses in the Superfluid Explorer.

Interacting with the Contract

Once you have deployed your contract, you can run your tests on your favourite framework. You can also test your smart contract live in the browser using the Superfluid Flow Sender Playground below. Modify yourAddress putting the address to your deployed contract and follow the steps on the interface below.

Live Editor
function FlowSenderPlayground() {

const yourAddress="0xe8f9eEDf7f171111169C71119cd625ee629E9831";
return (
    <div>
      <FlowSenderComponent contractAddress={yourAddress} />
    </div>
  );
}
Result
Loading...

Further Exploration

Understanding Super Tokens

Super Tokens are the core of Superfluid, offering real-time finance capabilities. Learn about how these upgraded ERC-20 tokens enable new financial primitives.

Exploring Money Streaming

Money Streaming is a novel concept introduced by Superfluid, allowing continuous and instant value transfer over time.

Diving into Distributions

Distributions are a key feature for scalable one-to-many payments in Superfluid. Learn how you can leverage distributions for various use cases.