This SDK helps developers get started with the on-chain raffle 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.
- Raffle:
RFLr7rHbJpw7Zvzu554h2AMtm34ng5SkzhytUWch2mb
- Project:
prjzeH8Jr5cbwMbzP8BykkRnW88MQ9pcRbqkvL74ewK
To setup a raffle 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 raffles. |
If you are interested on creating project using package, check out "Create Raffle using package" section
You can create Raffle
for you project by first go to your project page and then create raffle page or simply go to this link:
https://labs.blockasset.co/projects/<project-id>/create-raffle
Attribute | Type | Required | Description |
---|---|---|---|
Category | String | No | Raffle Category to be saved on chain |
Prize Mint | PublicKey | Yes | Mint address of the NFT that will be sent to the winner once the raffle 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 raffle |
Start | BN | Yes | Raffle start timestamp |
End | BN | Yes | Raffle end timestamp |
Max Tickets Per User | Number | Yes | Maximum percentage of the entries that each wallet can obtain |
If you are interested on creating raffle using package, check out "Create Project using package" section
Your users can participate in your raffle by going to this address: https://labs.blockasset.co/projects/<rafflee-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/raffle
You can also use npm instead, if you'd like:
npm install @blockassetlabs/project @blockassetlabs/raffle
🔥 Pro Tip: Check out our implementations on "BlockassetLabs UI" repository.
import { getProject } from "@blockassetlabs/project";
const project = getProject(connection, projectId);
import { getRafflesByProjectId } from "@blockassetlabs/raffle";
const raffles = await getRafflesByProjectId(connection, projectId);
import { getRaffle } from "@blockassetlabs/raffle";
const raffles = await getRaffle(connection, raffleId);
import { getTickets } from "@blockassetlabs/raffle";
const raffles = await getTickets(connection, ticketId);
This transaction can only be called by one of the project authorities
import { createRaffle } from "@blockassetlabs/raffle";
const { signature, raffleId } = await createRaffle(
connection,
wallet as Wallet,
{
// Project Id
projectId: project.pubkey,
// Mint address of raffle 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 raffle entrance in natural amounts
ticketFee: new BN(formValues.ticketFee),
// Total tickets of a raffle
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 { updateRaffle } from "@blockassetlabs/raffle";
const signature = await updateRaffle(connection, wallet as Wallet, {
// Raffle Id
raffleId: activeRaffle.pubkey,
// Project Id
projectId: project.pubkey,
// Mint address of raffle 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 raffle entrance in natural amounts
ticketFee: new BN(formValues.ticketFee),
// Total tickets of a raffle
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/raffle";
const signature = await redeemTickets(connection, wallet as Wallet, {
// Number of tickets
quantity,
// Raffle id
raffleId: activeRaffle.pubkey,
});
Resolving the raffle is an on-chain weighted random selection
This is a public transaction, so anybody can resolve the raffle
import { resolveRaffle } from "@blockassetlabs/raffle";
const signature = await resolveRaffle(
new Transaction(),
connection,
wallet as Wallet,
{
// Raffle id
raffleId: activeRaffle.pubkey,
},
);
Only the raffle winner can call call this transaction to claim its prize
import { claimPrize } from "@blockassetlabs/raffle";
const signature = await claimPrize(connection, wallet as Wallet, {
// Raffle id
raffleId: activeRaffle.pubkey,
});
It's possible to recover the funds used to pay rent for the data stored on-chain by closing the Raffle.
- 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 raffle.
This transaction can only be called by one of the project authorities
import { closeRaffle } from "@blockassetlabs/raffle";
const signature = await closeRaffle(connection, wallet as Wallet, {
// Raffle id
raffleId: activeRaffle.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 raffles, it's highly recommended to close its raffles first because once the project closed, you will no longer have access to its raffles 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.