Introduction
K2 SDK is a typescript SDK which can be used to interact with the K2 Lending protocol.
Installation
To install the SDK use the command npm i @blockswaplab/k2-sdk
Using the K2 SDK
One of the ways to import and initialise the SDK is:
import { K2 } from "@blockswaplab/k2-sdk";
const provider = new ethers.InfuraProvider(
"goerli",
INFURA_PROJECT_ID,
INFURA_PROJECT_SECRET,
);
const signer = new ethers.Wallet(PRIV_KEY, provider);
const sdk = new K2(signer);
For using the fundSplitter
sub-class, the SDK instance can be initialised with the fund splitter contract address as follows:
const sdk = new K2(signer, fundSplitterAddress);
The SDK supports both
goerli
(until it is deprecated) andmainnet
, hence the user should choose the network as per the need.
Please note that the SDK is an
ethers.js
based SDK and hence requiresethers
based signer instance. It also returns values inethers.js
supported format. For example, it returnsBigNumbers
for the smart contract view functions that might returnuint
.
Also note that K2 SDK v2 uses ethers v6(recommended). If you are using K2 SDK v1 which makes use of ethers v5, please create the signer and provider instances in the following way:
const provider = new ethers.providers.InfuraProvider("goerli", {
projectId: INFURA_PROJECT_ID,
projectSecret: INFURA_PROJECT_SECRET
});
const signer = new ethers.Wallet(PRIV_KEY, provider);
The SDK exposed following sub-classes: