Skip to main content

Interact On-Chain

This guide delves into the specifics of Superfluid's smart contract functions, offering step-by-step guidance and practical insights for developers looking to integrate Superfluid Money Streaming into their applications.

Building on top of the Superfluid's Money Streaming involves interacting with Super Tokens. Remember, Superfluid is a token-centric protocol, and all of the primitives are centered around Super Tokens.

When interacting with Super Tokens on-chain, you can use the Superfluid's SuperTokenV1Library to access the core functions.

Direct Interaction Functions

Read functions

These functions from the SuperTokenV1Library allow direct interactions with Super Tokens, providing real-time information about ongoing flows.


function getFlowInfo(ISuperToken token, address sender, address receiver)
internal view
returns(uint256 lastUpdated, int96 flowRate, uint256 deposit, uint256 owedDeposit)

Usage: Retrieve flow information, such as the rate and deposit details, between two accounts for a given Super Token. Useful for tracking and auditing ongoing streams.

Write functions

These functions allow direct interactions with Super Tokens, providing real-time information about ongoing flows.


function createFlow(ISuperToken token, address receiver, int96 flowRate)
internal returns (bool)

Usage: Create a flow to a receiver while specifying a flowRate.

About Create, Update, and Delete Flow Functions

Check our specific guide for Create, Update, and Delete Flow Functions for more details on these functions.

Functions with User Data and Context

User Data Overload

These advanced functions allow passing additional userData for custom operations.


// Same function call just with additional parameter for user data
token.createFlow(address receiver, int96 flowRate, bytes memory userData);
token.updateFlow(address receiver, int96 flowRate, bytes memory userData);
token.deleteFlow(address sender, address receiver, bytes memory userData);

Usage: Attach custom userData to your flow transactions. This feature is crucial for applications that require additional data to be transmitted or stored with each flow operation.

Context in Super App Callbacks

These functions allow passing additional ctx for custom operations related to Super App callbacks.

function onFlowCreated(ISuperToken superToken, address sender, bytes calldata ctx)
internal override returns (bytes memory /*newCtx*/) {
// ... callback logic
}

Usage: In Super App callbacks, use context (ctx) to manage state throughout the flow lifecycle. This is particularly important for apps that react to flow creations, updates, or deletions.

Access Control List Functions

The Access Control List (ACL) in Superfluid allows any account (either an external account or a smart contract) to configure permissions for another account to manage streams on its behalf. It's akin to the money streaming version of the ERC20 approval mechanism. For more details, check our ACL guide.

setFlowPermissions


function setFlowPermissions(
ISuperToken token,
address flowOperator,
bool allowCreate,
bool allowUpdate,
bool allowDelete,
int96 flowRateAllowance
) internal returns (bool)

Usage: Grant specific flow permissions to an operator. This function is key for delegating flow management responsibilities, similar to setting allowances in ERC20 tokens.