lottery-vrf-sdk
v2.0.1
Published
TypeScript SDK for Orao VRF
Readme
Lottery VRF SDK
This is an sdk, connect to the Lottery VRF program on Solana.
Draw
An user can draw a random number from the VRF. Each time he draws, a new random number PDA account is generated to store the random number, using ORAO VRF.
import { Keypair, PublicKey } from "@solana/web3.js";
import { LotteryDrawClient } from "../src";
export const getWallet = (
) => {
return Keypair.fromSecretKey(
Uint8Array.from(require(`/root/.config/solana/id.json`))
);
};
async function main() {
const keypair = getWallet();
const client = new LotteryDrawClient(keypair);
const txHash = await client.draw();
console.log(`Transaction: ${txHash}`);
}
main();User: GyPcdYe7JrM3W172JecLvS9xUEScjQWhARHyYqT9mj8J, draw round: 2
Transaction: fyZ5op2N5RrEE4U9sMmyzkmvRQdTYxu1hkwV3VVnzW67goxvWSoovzScFrg5Tew91aJ1AV53qD6naDZ4mgNFYUsFor each round user draw, a draw PDA account in the program is creataed to store the associated information
Get Draw
This function, get the draw information from the program. Then, it will wait for the VRF to be fulfilled and return the draw information, including the randomness data.
import { Keypair, PublicKey } from "@solana/web3.js";
import { LotteryDrawClient } from "../src";
async function main() {
const client = new LotteryDrawClient();
const draw = await client.getDraw(new PublicKey("GyPcdYe7JrM3W172JecLvS9xUEScjQWhARHyYqT9mj8J"), 2);
console.log("Drawer: ", draw.drawer.toBase58());
console.log("Round: ", draw.round);
console.log("Randomness: ", draw.randomness);
console.log("Randomness Account: ", draw.randomnessAccount.toBase58());
// Get randomness data in biguint64LE format
const randomness = Buffer.from(draw.randomness).readBigUInt64LE();
console.log("Randomness in biguint64LE LE: ", randomness.toString());
}
main();➜ orao-vrf-sdk git:(main) ✗ ts-node examples/getDraw.ts
Drawer: 8ekXR9PUuUUwmupGFLw3xTo1BFeRdescCGdwqMpK2swg
Round: <BN: 2>
Randomness: Uint8Array(64) [
191, 0, 106, 104, 237, 215, 175, 44, 47, 56, 242,
6, 104, 156, 42, 99, 136, 251, 222, 21, 41, 141,
12, 27, 223, 126, 235, 114, 148, 49, 97, 140, 100,
138, 221, 50, 30, 79, 253, 35, 86, 153, 233, 180,
240, 17, 66, 99, 3, 182, 206, 202, 149, 17, 115,
114, 151, 114, 200, 99, 15, 1, 77, 9
]
Randomness Account: 8REuCAFtP4FA7vsXE8Qtw2JuLrgozLNKWGXZUUDHCsPj
Randomness in biguint64LE LE: 3220029673252192447