Integrate with Cyan in ~1hr!
https://github.com/usecyan/sdk
Install Cyan SDK
npm install @usecyan/sdk
yarn add @usecyan/sdk
Usage
Initialize the SDK instance with an API key, your current web3 provider, and Host URI
import {Cyan} from '@usecyan/sdk'
const apiKey = process.env.CYAN_API_KEY
const provider ... // your web3 provider
const host = 'https://testnet-api.usecyan.com'
const cyan = new Cyan({apiKey, provider, host})
Method references
acceptPlanInfo
Gets acceptance signature with given calculated data (IBnplPrice or IPawnPrice).
async function acceptPlanInfo(
chain: IChain, // required, chain slug (ex: mainnet, goerli)
data: IBnplPrice | IPawnPrice, // required
wallet: string // required
): Promise<void>
checkApproval
Checks current token has given approval to Cyan wrapper contract. getApproval method calls this method internally.
async function checkApproval(
address: string, // required
pawn: IPawnPrice // required
): Promise<boolean> // true or false
createBnpl
Creates BNPL plan with given calculated data (IBnplPrice) returned from getBnplPrices.
async function createBnpl(
calculatedData: ICalcResponse // required
): Promise<ContractTransaction> //Ethers.js ContractTransaction type
createPawn
Creates Pawn plan with given calculated data (IPawnPrice) returned from getPawnPrice.
async function createPawn(
calculatedData: IPawnPrice // required
): Promise<ContractTransaction> //Ethers.js ContractTransaction type
getBnplPrices
Retrieves array of calculated data (IBnplPrice) for given NFTs (Array of addresses and token Ids).
async function getBnplPrices(
chain: IChain, // required, chain slug (ex: mainnet, goerli)
nfts: Nft[], // required
walletAddress: string // required
): Promise<IBnplPrice>
type Nft = {
address: string;
tokenId: string;
};
getPawnAppraisals
Retrieves array of Appraisal(IApprasal) values for given NFTs. If NFT is not supported it will throw an error saying Error: Project is not supported yet.
async function getPawnAppraisals(
chain: IChain, // required, chain slug (ex: mainnet, goerli)
nfts: Nft[] // required
): Promise<IAppraisal[] | IAppraisalError[]>
type Nft = {
address: string;
tokenId: string;
};
getPawnPrice
Retrieves an Appraisal data (IPawnPrice) for given NFT and parameters.
async function getPawnPrice(
chain: IChain, // required, chain slug (ex: mainnet, goerli)
address: string, // required, NFT collection address
tokenId: string, // required, NFT id
pawnType: PawnType //required
): Promise<IPawnPrice[]>
type PawnType = {
term: number;
totalNumOfPayments: number;
weight: 20 | 33 | 50;
wallet: string;
}
{
totalNumOfPayments: 3,
weight: 20,
term: 2678400,
wallet: UserWalletAddress
}
{
totalNumOfPayments: 3,
weight: 33,
term: 2678400,
wallet: UserWalletAddress
}
{
totalNumOfPayments: 1,
weight: 50,
term: 86400,
wallet: UserWalletAddress
}
getPlan
Retrieves Activated (status) plan (IPlan) to given NFT (address, tokenId).
async function getPlan(
address: string,// required
tokenId: string // required
): Promise<IPlan>
getUserPlans
Retrieves user plans (Array of IPlan) with the status Activated, Funded, Pending
async function getUserPlans(
walletAddress: string //required
): Promise<IPlan[]>
getApproval
Asks for approval from the user in order to initiate the Pawn process. If approved returns true
.
async function getApproval(
address: string, //required
pawn: IPawnPrice //required
): Promise<boolean> // true or false
getNextPayment
Retrieves next payment data (INextPayment) for the given Active plan which is returned from getPlan.
async function getNextPayment(
plan: IPlan //required
): Promise<INextPayment>
pay
Asks to make the payment for the plan (BNPL or Pawn).
async function pay(
plan: IPlan, //required
amount: BigNumber //required
): Promise<ContractTransaction> //Ethers.js ContractTransaction type