tonstakers-sdk v0.0.7-development
Tonstakers SDK
The Tonstakers SDK offers an advanced set of tools for developers aiming to incorporate staking functionalities into their applications on the TON blockchain. This updated version introduces a more extensive interaction with the TON ecosystem, including staking operations, balance inquiries, and much more, enhancing your application's capabilities.
Features
- Simplified staking and unstaking operations, including options for maximum stake, instant unstake, and best rate unstake.
- Retrieval of staked, available, TVL (Total Value Locked), and stakers count balances.
- Fetching current and historical APY (Annual Percentage Yield) for staked assets.
- Enhanced API key configuration for improved access limits to the tonapi.
- Event-driven architecture for initialization and deinitialization notifications.
Installation
Tonstakers SDK can be easily installed using npm or yarn, or integrated directly into your HTML pages.
Using npm or yarn
npm install tonstakers-sdk
# or
yarn add tonstakers-sdk
Using a <script>
tag
For direct HTML integration:
<script src="path/to/tonstakers-sdk.min.js"></script>
Replace "path/to/tonstakers-sdk.min.js"
with the actual SDK path.
Usage
In a Module Environment
Initialize the SDK with your wallet connector (usually, a TonConnect instance) and optional parameters:
import { Tonstakers } from "tonstakers-sdk";
// this is an example connector
import { TonConnectUI } from "@tonconnect/ui";
export const tonConnectUI = new TonConnectUI({
manifestUrl: MANIFEST_URL,
});
const tonstakers = new Tonstakers({
connector: yourWalletConnector, // Your wallet connector
partnerCode: 123456, // Optional partner code
tonApiKey: "YOUR_API_KEY", // Optional API key for tonapi
});
In a Browser Environment
Direct HTML file initialization:
<script src="path/to/tonstakers-sdk.min.js"></script>
<script>
const { Tonstakers } = TonstakersSDK;
const tonstakers = new Tonstakers({
connector: yourWalletConnector,
partnerCode: 123456,
tonApiKey: "YOUR_API_KEY",
});
</script>
Event Listeners
tonstakers.addEventListener("initialized", () => {
console.log("Tonstakers SDK initialized successfully.");
});
tonstakers.addEventListener("deinitialized", () => {
console.log("Tonstakers SDK has been deinitialized.");
});
Performing Operations
Stake and unstake with new methods:
await tonstakers.stake(1); // Stake 1 TON
await tonstakers.unstake(1); // Unstake 1 tsTON
await tonstakers.stakeMax(); // Stake the maximum available balance
await tonstakers.unstakeInstant(1); // Instant unstake 1 tsTON
await tonstakers.unstakeBestRate(1); // Unstake 1 tsTON at the best available rate
Retrieve information:
const stakedBalance = await tonstakers.getStakedBalance();
console.log(`Current staked balance: ${stakedBalance}`);
const availableBalance = await tonstakers.getAvailableBalance();
console.log(`Available balance for staking: ${availableBalance}`);
const currentApy = await tonstakers.getCurrentApy();
console.log(`Current APY: ${currentApy}%`);
const historicalApy = await tonstakers.getHistoricalApy();
console.log(`Historical APY data: ${historicalApy}`);
const tvl = await tonstakers.getTvl();
console.log(`Total Value Locked (TVL): ${tvl}`);
const stakersCount = await tonstakers.getStakersCount();
console.log(`Current number of stakers: ${stakersCount}`);
const rates = await tonstakers.getRates();
console.log(`1 TON = ${rates.TONUSD} USD`);
console.log(`1 tsTON = ${rates.tsTONTON} TON`);
console.log(`Projected 1 tsTON = ${rates.tsTONTONProjected} TON`);
Demo
A demo HTML page is included with the SDK to demonstrate integration into web applications, showcasing wallet connection, staking/unstaking operations, and balance updates.
3 months ago
4 months ago
5 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago