This SDK helps developers get started with the on-chain staking tool provided by Blockasset Labs. It focuses its API on common use-cases to provide a smooth developer experience.
Program addresses are the same on devnet, and mainnet-beta.
- Staking:
RFLr7rHbJpw7Zvzu554h2AMtm34ng5SkzhytUWch2mb
- Project:
prjzeH8Jr5cbwMbzP8BykkRnW88MQ9pcRbqkvL74ewK
To setup a staking you need to have a Project
first. If you don't have one, easiest way to create your own project is by using blockasset labs "Create Project" page.
Attribute | Type | Required | Description |
---|---|---|---|
name | String | Yes | Project name |
authorities | Array | Yes | List of authorities who have access to update project detail and create, update, or close project stakings. |
If you are interested on creating project using package, check out "Create Staking using package" section
You can create Staking
for you project by first go to your project page and then create staking page or simply go to this link:
https://labs.blockasset.co/projects/<project-id>/create-staking
Attribute | Type | Required | Description |
---|---|---|---|
Category | String | No | Staking Category to be saved on chain |
Prize Mint | PublicKey | Yes | Mint address of the NFT that will be sent to the winner once the staking resolved |
Token Mint | PublicKey | Yes | Mint address of the token that will be used as payment for purchasing the tickets |
Ticket Price | BN | Yes | Price of each tickets in lamports |
Max Tickets | Number | Yes | Maximum number of tickets in each staking |
Start | BN | Yes | Staking start timestamp |
End | BN | Yes | Staking end timestamp |
Max Tickets Per User | Number | Yes | Maximum percentage of the entries that each wallet can obtain |
If you are interested on creating staking using package, check out "Create Project using package" section
Your users can participate in your staking by going to this address: https://labs.blockasset.co/projects/<stakinge-id>
Attribute | Type | Required | Description |
---|---|---|---|
quantity | Number | Yes | Number of entries that user wants to obtain |
Installing the package using yarn:
yarn add @blockassetlabs/project @blockassetlabs/staking
You can also use npm instead, if you'd like:
npm install @blockassetlabs/project @blockassetlabs/staking
🔥 Pro Tip: Check out our implementations on "BlockassetLabs UI" repository.
import { getProject } from "@blockassetlabs/project";
const project = getProject(connection, projectId);
import { getStakingsByProjectId } from "@blockassetlabs/staking";
const stakings = await getStakingsByProjectId(connection, projectId);
import { getStaking } from "@blockassetlabs/staking";
const stakings = await getStaking(connection, stakingId);
import { getTickets } from "@blockassetlabs/staking";
const stakings = await getTickets(connection, ticketId);
This transaction can only be called by one of the project authorities
import { createStaking } from "@blockassetlabs/staking";
const { signature, stakingId } = await createStaking(
connection,
wallet as Wallet,
{
// Project Id
projectId: project.pubkey,
// Mint address of staking prize NFT
prizeMint: new PublicKey(formValues.prizeMint),
// Mint address of the acceptable token for entrance fee
// If not provided the payment will be based on sol
tokenMint: formValues.tokenMint ?? new PublicKey(formValues.tokenMint),
// Wallet address of treasury account for the entrance fees
// No need to set any if the burn rate is 100
treasury: formValues.tokenMint ?? new PublicKey(formValues.treasury),
// Burn rate of the tokenMint
// Can be between 1 to 100
burnRate: formValues.burnRate ?? new PublicKey(formValues.burnRate),
// Entrance fee for acquiring 1 staking entrance in natural amounts
ticketFee: new BN(formValues.ticketFee),
// Total tickets of a staking
maxTickets: formValues.maxTickets,
// Maximum percentage of the total tickets that each wallet can redeem
// Default is 100
maxTicketsPerWalletRate: formValues.maxTicketsPerWalletRate,
// Start date timestamp
start: new BN(formValues.start.getTime() / 1000),
// End date timestamp
end: new BN(formValues.end.getTime() / 1000),
// Additional info
category: formValues.category,
},
);
This transaction can only be called by one of the project authorities
import { updateStaking } from "@blockassetlabs/staking";
const signature = await updateStaking(connection, wallet as Wallet, {
// Staking Id
stakingId: activeStaking.pubkey,
// Project Id
projectId: project.pubkey,
// Mint address of staking prize NFT
prizeMint: new PublicKey(formValues.prizeMint),
// Mint address of the acceptable token for entrance fee
// If not provided the payment will be based on sol
tokenMint: formValues.tokenMint ?? new PublicKey(formValues.tokenMint),
// Wallet address of treasury account for the entrance fees
// No need to set any if the burn rate is 100
treasury: formValues.tokenMint ?? new PublicKey(formValues.treasury),
// Burn rate of the tokenMint
// Can be between 1 to 100
burnRate: formValues.burnRate ?? new PublicKey(formValues.burnRate),
// Entrance fee for acquiring 1 staking entrance in natural amounts
ticketFee: new BN(formValues.ticketFee),
// Total tickets of a staking
maxTickets: formValues.maxTickets,
// Maximum percentage of the total tickets that each wallet can redeem
// Default is 100
maxTicketsPerWalletRate: formValues.maxTicketsPerWalletRate,
// Start date timestamp
start: new BN(formValues.start.getTime() / 1000),
// End date timestamp
end: new BN(formValues.end.getTime() / 1000),
// Additional info
category: formValues.category,
});
This is a public transaction and can only be called by anyone
import { redeemTickets } from "@blockassetlabs/staking";
const signature = await redeemTickets(connection, wallet as Wallet, {
// Number of tickets
quantity,
// Staking id
stakingId: activeStaking.pubkey,
});
Resolving the staking is an on-chain weighted random selection
This is a public transaction, so anybody can resolve the staking
import { resolveStaking } from "@blockassetlabs/staking";
const signature = await resolveStaking(
new Transaction(),
connection,
wallet as Wallet,
{
// Staking id
stakingId: activeStaking.pubkey,
},
);
Only the staking winner can call call this transaction to claim its prize
import { claimPrize } from "@blockassetlabs/staking";
const signature = await claimPrize(connection, wallet as Wallet, {
// Staking id
stakingId: activeStaking.pubkey,
});
It's possible to recover the funds used to pay rent for the data stored on-chain by closing the Staking.
- If the prize is not claimed yet this action will transfer back the prize to the caller account.
- This action is not recoverable and permanently remove the access to the staking.
This transaction can only be called by one of the project authorities
import { closeStaking } from "@blockassetlabs/staking";
const signature = await closeStaking(connection, wallet as Wallet, {
// Staking id
stakingId: activeStaking.pubkey,
});
This is a public transaction, so anybody can create a new project
import { withInitProject } from "@blockassetlabs/project";
const [transaction, projectId] = await withInitProject(
new Transaction(),
connection,
wallet as Wallet,
{
authorities: [wallet.publicKey],
name: formValues.name,
},
);
await executeTransaction(connection, wallet as Wallet, transaction, {
silent: false,
signers: [],
});
This transaction can only be called by one of the project authorities
import { withUpdateProject } from "@blockassetlabs/project";
const transaction = await withUpdateProject(
new Transaction(),
connection,
wallet as Wallet,
{
projectId: projectId,
authorities: [wallet.publicKey],
name: formValues.name,
},
);
await executeTransaction(connection, wallet as Wallet, transaction, {
silent: false,
signers: [],
});
It's possible to recover the funds used to pay rent for the data stored on-chain by closing the Project.
- Although closing a project will not affect any of its stakings, it's highly recommended to close its stakings first because once the project closed, you will no longer have access to its stakings to modify or close.
- This action is not recoverable and permanently remove the access to the project.
This transaction can only be called by one of the project authorities
import { withUpdateProject } from "@blockassetlabs/project";
const transaction = await withCloseProject(
new Transaction(),
connection,
wallet as Wallet,
{
projectId: projectId,
},
);
await executeTransaction(connection, wallet as Wallet, transaction, {
silent: false,
signers: [],
});
If you are developing using Blockasset contracts and libraries, feel free to reach out for support on Discord. We will work with you or your team to answer questions, provide development support and discuss new feature requests.
For issues please, file a GitHub issue.