Skip to main content

Initialization

This guide provides step-by-step instructions on how to initialize and use the Superfluid SDK Core.

Initialization

Required Imports

To work with the Superfluid SDK Core, ensure your project includes graphql and ethers as dependencies. You can install the Superfluid SDK Core with the following command:

npm install @superfluid-finance/sdk-core

Peer Dependencies

Along with the SDK, you'll need graphql and ethers.js. Install them using:

npm install graphql ethers

Initializing the SDK Core

Create the Superfluid Framework using Framework.create():

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID, e.g., 137 for Polygon
provider: ethersProvider, // Replace with your ethers provider
});

Framework Options

The Framework.create() method requires the following options:

  • chainId (number): The chain ID of the network.
  • provider (SupportedProvider): The ethers provider being used.

The Signer Class [Optional]

Web3Provider Signer Example

For client-side applications, you can create a signer using the Web3Provider object:

import { Framework } from "@superfluid-finance/sdk-core";
import Web3Modal from "web3modal";
import { Web3Provider } from "@ethersproject/providers";

// Web3Modal example
const web3ModalRawProvider = await web3Modal.connect();
const web3ModalProvider = new Web3Provider(web3ModalRawProvider, "any");

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider: web3ModalProvider,
});

const web3ModalSigner = sf.createSigner({ web3Provider: web3ModalProvider });

// MetaMask example
const metamaskProvider = new Web3Provider(window.ethereum);
const metaMaskSigner = sf.createSigner({ web3Provider: metamaskProvider });

Hardhat Signer Example

In a Hardhat + ethers.js environment, create a signer like this:

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "hardhat";

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider: ethers.provider,
});

const signer = sf.createSigner({
privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>",
provider: ethers.provider,
});

Signer/Wallet Example

For Node.js or back-end environments, create a signer using a wallet:

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";

const provider = new ethers.providers.InfuraProvider(
"matic",
"<INFURA_API_KEY>"
);

const wallet = new ethers.Wallet(
"<WALLET_PRIVATE_KEY>",
provider
);

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider,
});

const signer = sf.createSigner({ signer: wallet });

Operations

The Operation class is returned after executing a contract call, which can then be used to broadcast the transaction or create a BatchCall.

import { Framework } from "@superfluid-finance/sdk-core";
import { ethers } from "ethers";

const provider = new ethers.providers.InfuraProvider(
"matic",
"<INFURA_API_KEY>"
);

const sf = await Framework.create({
chainId: 137, // Replace with your chain ID
provider
});

// Create a signer
const signer = sf.createSigner({ privateKey: "<TEST_ACCOUNT_PRIVATE_KEY>", provider });

// Load the USDCx SuperToken
const usdcx = sf.loadSuperToken("0xCAa7349CEA390F89641fe306D93591f87595dc1F");

// Create and execute an approve operation
const approveTxn = await usdcx.approve({ receiver: "0xab...", amount: ethers.utils.parseUnits("100").toString() }).exec(signer);
const approveTxnReceipt = await approveTxn.wait();

This guide covers the essential steps and options for initializing and using the Superfluid SDK Core. Replace placeholders with actual values specific to your project and use case.