You'll need to have a project which already includes graphql and ethers as dependencies.
From here, you can install the Superfluid SDK Core like so:
npm install @superfluid-finance/sdk-core
Peer Dependencies
You'll also need to install graphql and ethers.js to work with the SDK.
npm install graphql ethers
Initializing the SDK Core
When creating the framework, you'll use Framework.create() like so:
const sf = await Framework.create({
chainId: Number, //i.e. 137 for matic
provider: ethersProvider // i.e. the provider being used
});
Framework Options
When creating the framework, you must pass in the following options. The only required params are the provider and a chainId
chainId: number - the chain Id for the network
provider: SupportedProvider - the provider being used
The Signer Class [Optional]
Web3Provider Signer Example
Below is an example of using the Web3Provider object to create a signer. This will likely be the way that most client-side applications create a signer.
Below is an example of creating a signer in a Hardhat + ethers.js environment. This will likely be the way that the sdk-core is used in a testing environment.
Below is an example of creating a signer passing in a signer object (this can be a wallet for example). This will likely be the way that the sdk-core is used in a Node.js environment (back-end) or a testing environment.
The Operation class is an object that is returned after you execute a contract call from this package - instead of immediately executing, we return the Operation class which can be either executed to broadcast the transaction or used to create and execute a BatchCall. We'll make use of this class in our next sections.
import { Framework } from"@superfluid-finance/sdk-core";import { ethers } from"ethers";constprovider=newethers.providers.InfuraProvider("matic","<INFURA_API_KEY>");constsf=awaitFramework.create({ chainId:137,//this is for matic - enter your own chainId here provider});// create a signerconstsigner=sf.createSigner({ privateKey:"<TEST_ACCOUNT_PRIVATE_KEY>", provider });// load the usdcx SuperToken via the Frameworkconstusdcx=sf.loadSuperToken("0xCAa7349CEA390F89641fe306D93591f87595dc1F");// create an approve operationconstapproveOperation=usdcx.approve({ receiver:"0xab...", amount:ethers.utils.parseUnits("100").toString() });// execute the approve operation, passing in a signerconsttxn=awaitapproveOperation.exec(signer);// wait for the transaction to be confirmedconstreceipt=awaittxn.wait();// or you can create and execute the transaction in a single lineconst approveTxn = await usdcx.approve({ receiver: "0xab...", amount: ethers.utils.parseUnits("100").toString() }).exec(signer);
constapproveTxnReceipt=awaitapproveTxn.wait();