@folks-finance/folks-staking-sdk
v0.0.3
Published
The official JavaScript SDK for the $FOLKS Staking
Readme
@folks-finance/folks-staking-sdk
JavaScript SDK for Folks staking.
Table of Contents
Getting Started
Installation
Package manager
Using npm:
npm install @folks-finance/folks-staking-sdkUsing yarn:
yarn add @folks-finance/folks-staking-sdkUsing pnpm:
pnpm add @folks-finance/folks-staking-sdkUsing bun:
bun add @folks-finance/folks-staking-sdkSDK Structure and Usage
Initialize FolksCore before calling any other method. It accepts an optional Config object — if omitted, it defaults to the testnet configuration.
import { FolksCore, FolksStaking, CONFIG } from "@folks-finance/folks-staking-sdk";
// Use default testnet config
FolksCore.init();
// Or pass a custom config (e.g. mainnet once deployed)
FolksCore.init(CONFIG.TESTNET);For write operations, also set a signer:
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { bscTestnet } from "viem/chains";
const signer = createWalletClient({
account: privateKeyToAccount("0x..."),
chain: bscTestnet,
transport: http(),
});
FolksCore.setSigner(signer);SDK main component FolksStaking contains such methods:
- Read state (
read):getStakingPeriods()getUserStakes(address)getClaimable(address, stakeIndex)activeTotalStaked()activeTotalRewards()isPaused()
- Submit transactions (
write):stake(periodIndex, amount, maxStakingDurationSeconds, maxUnlockDurationSeconds, minAprBps, referrer?)stakeWithPermit(periodIndex, amount, maxStakingDurationSeconds, maxUnlockDurationSeconds, minAprBps, referrer?, permitDeadline?)withdraw(stakeIndex)
stakeWithPermit is implemented according to ERC-2612, which allows users to submit only one transaction on chain. stake uses an approval transaction.
referrer is an optional field.
permitDeadline is an optional field (by default, the permit expires in 20 minutes).
Usage
Examples provided in ./examples folder.
