1.0.0 • Published 6 months ago
fsd-protocol-sdk v1.0.0
Fairside Protocol SDK
Overview
The Fairside Protocol SDK (@fsd/sdk
) is a powerful tool that enables seamless integration and interaction with the Fairside Protocol platform. This SDK offers methods to interact with both the API and smart contract modules, facilitating user actions such as membership purchases, renewals, and metadata handling.
Installation
To install the Fairside Protocol SDK in your project, use the following npm command:
npm install @fsd/sdk
yarn add @fsd/sdk
Configuration
Initialization
import { FsdSDK, Env, SupportedCurrency, ConfigEnv } from "@fsd/sdk";
const { api, contract } = FsdSDK({
apiKey: "YOUR_API_KEY", // Replace with your API key
env: Env.DevNet, // Specify the environment (DevNet, TestNet, MainNet)
});
Usage
API Module Integration
Save Message to Sign
const savesMessageRes = await api.saveMessageToSign("WALLET_ADDRESS");
Generate wallet signature using wagmi or any library of your choice
const signature = await signTypedDataAsync({
domain: {
name: "Fairside Protocol",
version: "1",
chainId: ConfigEnv.devNet.chainId,
},
types: {
Person: [{ name: "message", type: "string" }],
},
primaryType: "Person",
message: { message: savedMessageRes.walletMessageToSign },
});
Create or Login User
const loginRes = await api.createOrLoginUser({
walletAddress: savedMessageRes.walletAddress,
walletSignatureMessage: savedMessageRes.walletMessageToSign,
walletSignature: signature,
referralCode: "PARTNER_REFERRAL_CODE",
});
Accept Terms and Conditions
await api.acceptTermAndCondition({
walletAddress: saveMessageRes.walletAddress,
accessToken: loginRes.token,
});
Get User Payload
const user = await api.getUser({
walletAddress: saveMessageRes.walletAddress,
accessToken: loginRes.token,
});
Contract Module Integration
Purchase Membership
const purchaseTrx = await contract.purchaseMembership(
signer, // Wallet signer
{
costShareBenefit: 2, // 2 ETH
coveredAddress: "COVERED_ADDRESS",
});
Save Purchase Membership Metadata
await api.savePurchaseMembership({
walletAddress: "COVERED_ADDRESS",
transactionHash: purchaseTrx?.transactionHash,
coveredAddress: "COVERED_ADDRESS",
coveredAmount: 2,
currency: SupportedCurrency.ETH,
});
Get Wallet Address Cover Ids
const coverIds = await contract.getAccountCoverIds("WALLET_ADDRESS");
Top-Up Membership
const topUpTrx = await contract.topUpMembership(signer, {
costShareBenefit: 2,
coverId: "COVER ID",
});
Save Top-Up Membership Metadata
await api.saveTopUpMembership({
coverID: "COVER ID",
walletAddress: "COVERED_ADDRESS",
transactionHash: topUpTrx.transactionHash,
coveredAddress: "COVERED_ADDRESS",
coveredAmount: 2,
currency: SupportedCurrency.ETH,
});
Renew Membership
const renewTrx = await contract.purchaseMembership(
signer,
{
costShareBenefit: 2,
coverId: "COVER ID",
});
Save Renew Membership Metadata
await api.saveRenewMembership({
coverID: "COVER ID",
walletAddress: "COVERED_ADDRESS",
transactionHash: renewTrx.transactionHash,
coveredAddress: "COVERED_ADDRESS",
coveredAmount: 2,
currency: SupportedCurrency.ETH,
});
License
MIT License
1.0.0
6 months ago