Getting Started
Start building with the Superfluid SDK in minutes
The Superfluid SDK provides TypeScript/JavaScript bindings for interacting with the Superfluid Protocol, enabling real-time finance applications with continuous money streams.
Requirements
Before you begin, ensure you have:
- Node.js 18+ installed
- A package manager (npm, yarn, pnpm, or bun)
- Basic knowledge of TypeScript/JavaScript
- Understanding of Ethereum and smart contracts
Installation
Install the Superfluid SDK using your preferred package manager:
npm install @sfpro/sdk viem wagmi
pnpm add @sfpro/sdk viem wagmi
yarn add @sfpro/sdk viem wagmi
bun add @sfpro/sdk viem wagmi
The SDK has peer dependencies on viem
and wagmi
which provide the underlying Ethereum interaction capabilities.
Quick Start
Here's a minimal example to get you started with Superfluid. This example uses the CFA Forwarder (recommended approach) to create a token stream:
import {
cfaForwarderAbi,
cfaForwarderAddress
} from "@sfpro/sdk/abi"
import { calculateFlowrate } from "@sfpro/sdk/util"
import { createWalletClient, http, parseEther } from "viem"
import { mainnet } from "viem/chains"
import { privateKeyToAccount } from "viem/accounts"
const account = privateKeyToAccount("0x..." as `0x${string}`)
const client = createWalletClient({
account,
chain: mainnet,
transport: http()
})
async function startStream() {
// Calculate flowrate: 100 tokens per month
const flowrate = calculateFlowrate({
amountWei: parseEther("100"),
timeUnit: "month"
})
// Create stream using CFA Forwarder (recommended!)
const hash = await client.writeContract({
address: cfaForwarderAddress[mainnet.id],
abi: cfaForwarderAbi,
functionName: "setFlowrate",
args: [
"0x...", // Super Token address
"0x...", // Receiver address
flowrate // Tokens per second
]
})
return hash
}
Why Forwarders? The CFA and GDA Forwarders are the recommended way to interact with Superfluid. They handle the complexity of encoding agreement calls and routing them through the Host contract.
Package Structure
The SDK is organized into three main import paths:
@sfpro/sdk/abi
- Core ABIs and addresses (includes forwarders)@sfpro/sdk/util
- Utility functions (calculateFlowrate, OPERATION_TYPE, prepareOperation)@sfpro/sdk/action
- wagmi core actions for non-React usage@sfpro/sdk/hook
- React hooks for wagmi integration
Key Contracts
The SDK primarily exposes these contracts:
- CFA Forwarder - Manage continuous flows (recommended for streaming)
- GDA Forwarder - Manage distributions (recommended for pools)
- Super Token - Wrap/unwrap tokens and check balances
- Host - Core protocol contract (advanced usage only)
Next Steps
- Learn about Superfluid Protocol concepts
- Understand wagmi & viem integration
- Explore the SDK architecture
- Try the use-case guides