@bountygg/provably-fair
v1.1.1
Published
Hello from the bounty.gg team 👋
Downloads
2
Readme
Hello from the bounty.gg team 👋
We feel it's important to stay transparent, which is why we're making the official provably fair implementation used on the bounty.gg servers public here
Usage
const pf = require("@bountygg/provably-fair");
async function aQuickTestRun() {
const ticketCount = 10000; // lets pretend there are 10k tickets in the jackpot round
// generate a random string
const serverSeed = pf.getRandomBytes();
// get a random string from a third party (here random.org)
const thirdPartySalt = (await pf.getThirdPartySalt()).value;
// concat both seeds
const fullSeed = `${serverSeed}-${thirdPartySeed}`;
// get winning percentage based on both the locally-generated `serverSeed` and the third-party `thirdPartySeed`
// see https://chancejs.com/usage/seed.html for an example implementation
const winningPercentage = pf.getPseudoRandomPercentage(fullSeed);
// we're done! now we're able to get the winning ticket
const winningTicket = pf.getWinningTicket(winningPercentage, ticketCount);
console.table({
ticketCount,
serverSeed,
thirdPartySeed,
fullSeed,
winningPercentage: winningPercentage.toNumber(),
winningTicket
});
}
aQuickTestRun();
Run the example above with
RANDOM_ORG_API_KEY=\<your random.org api key\> node index.js
You can get a free api key for the random.org gRPC api from api.random.org