DogeJS / Doge on X / Giveaway picker

Giveaway picker

Tipping the replies? Paste the names, draw the winners, and show everyone the draw was fair.

Free, no account, nothing leaves your browser. For developers: the docs

The giveaway page on a phone: the draw locked with its fingerprint, a Post the lock on X button and the pasted entries.

What you get

Giveaway picker, step by step

The winners on a phone: three names in a numbered list, a Post the winners button and the winners image.

Draw the winners

Choose how many winners, then draw. The page shows the winners and a link that lets anyone re-run the draw.

  • Duplicates count once and the page tells you how many it removed
  • Order does not matter
  • Up to 10,000 entries and 100 winners
dogejs.com/x/giveaway/app/
The winners image: Giveaway winners with three names and a cheering doge.

A winners image to post

Get a picture with the winners and the fingerprint of the draw, ready to attach.

  • Made in your browser
  • Shows the fingerprint, so anyone can compare
  • Download or copy
The check view of the giveaway page on a phone: a green message saying the draw matches, with the same winners.

Anyone can check it

Readers open your check link, paste the same list, and get the same winners. A green result means the draw was fair.

  • A wrong fingerprint shows in red
  • No account, no server
  • The check link is part of your post
An illustration of a post box with the winners, the seed fingerprint and the check link.

Post the lock, then the winners

First post the fingerprint, before entries close. After the draw, post the winners with the check link.

  • The fingerprint fixes the draw before anyone knows the list
  • We never post for you
  • Works on phone and computer

How it works

  1. Lock the draw

    Post the fingerprint before entries close.

  2. Paste replies and draw

    The winners and a check link appear.

  3. Post the winners

    Anyone can re-run the draw and compare.

Questions

Can the host cheat?

The host cannot pick a seed after seeing the list, because its fingerprint was posted first. The host does choose who is on the list, so post the list or say where it came from.

Does the order I paste the replies in matter?

No. Entries are cleaned and sorted before the draw.

What if someone replies twice?

Duplicates count once; the page says how many it removed.

Does it send the prizes?

No. It writes a payout file when the winners are addresses; you pay with your wallet.

How many entries and winners?

Up to 10,000 entries and 100 winners.

Do I connect my X account?

No. Copy the names of the people who replied and paste them in.

Is this made by X?

No. DogeJS is an independent project and is not affiliated with X Corp. The tools only open X's own post box with the text filled in; you press Post yourself.

Giveaway picker

It works for real, right here. No sign-up.

For developers

The fair draw for developers

Commit, draw and reveal, the exact algorithm, and how to re-run a draw with or without DogeJS code.

How it works

  1. Commit. The page makes a random 32-byte seed and shows only its fingerprint, SHA-256 of the seed's 64 hex characters. The host posts the fingerprint before entries close, so the seed is fixed before anyone knows the list.
  2. Draw. Entries are cleaned (@name lower case, or an address), de-duplicated and sorted, so the order they were pasted in does not matter. The list fingerprint is SHA-256 of the ids joined with "\n". The key is SHA-256 of seed + "\n" + list fingerprint. A stream of 32-bit numbers comes from SHA-256(key || counter), counter as 4 big-endian bytes, starting at 0. Position i takes i + below(n - i) (partial Fisher-Yates), where below(n) rejects numbers at or above floor(2^32 / n) * n to avoid modulo bias.
  3. Reveal. The host posts the seed and a check link /x/giveaway/#c~<seed>~<count>~<first 16 of the list fingerprint>. Anyone pastes the same replies and gets the same winners; the page says if the list differs.

The host can still choose who is on the list. The draw shows the winners follow from a seed fixed in advance, and that the list was the one shown.

The check link holds the seed, the number of winners and the first 16 hex characters of the list fingerprint: https://dogejs.com/x/giveaway/#c~<64 hex>~<count>~<16 hex>. The list is not in the link (it can be long); the checker pastes it.

Use it in your own code

The package is @dogejs/xkit. It is not on npm yet: install it from its repository tag, then import the helpers. They are plain functions with no DOM at module level, so they run in Node 20+, in browsers and in workers.

Shell
npm install github:DogeJS-Dev/doge-on-x#v0.2.0
JavaScript
import { tipLink, decodeLink, checkProof, draw, postIntentUrl } from '@dogejs/xkit';

Run draws from a bot or a script with parseEntries, commitment and draw; let anyone check them with verifyDraw or the independent script below.

Code examples

Each example runs in Node against the built package; the output is recorded from that run and checked by npm run examples.

Reproduce a giveaway draw

Commit, paste replies, draw, make the check link, and verify it like a reader would. File examples/draw.mjs; run: node examples/draw.mjs.

JavaScript
// Reproduce a giveaway draw: commit, draw, reveal, check.
import { commitment, draw, encodeCheck, parseEntries, verifyDraw } from '@dogejs/xkit';

const seed = '7f3a9c51e2d84b06a1f0c3e5d7b9a2c4e6f8091b3d5f7a9c0e2b4d6f8a1c3e5d'; // newSeed() makes a random one
console.log('post first:', commitment(seed));      // the fingerprint, posted before entries close

const replies = `@shibe_one wow count me in
@Shibe_Two
much want @shibe_three and @shibe_four
@shibe_one again`;
const { entries, duplicates } = parseEntries(replies);
console.log(entries.map((e) => e.id).join(' '), '| duplicates:', duplicates);

const result = draw(seed, entries, 2);
console.log('winners:', result.winners.map((w) => w.id).join(', '));
console.log('check link: https://dogejs.com/x/giveaway/#' + encodeCheck(seed, 2, result.listHash));

// Anyone re-runs it from the revealed seed, the posted fingerprint and the same replies:
const check = verifyDraw({ seed, entries: replies, count: 2, commit: commitment(seed), listPrefix: result.listHash.slice(0, 16) });
console.log(check.ok, check.commitMatches, check.listMatches, check.winners.map((w) => w.id).join(', '));
Output
post first: 4793e416d06cf6ce7aa520374bb4d0870f7d0ab7f714bfa2620ed670cb63eacd
@shibe_four @shibe_one @shibe_three @shibe_two | duplicates: 1
winners: @shibe_three, @shibe_two
check link: https://dogejs.com/x/giveaway/#c~7f3a9c51e2d84b06a1f0c3e5d7b9a2c4e6f8091b3d5f7a9c0e2b4d6f8a1c3e5d~2~f5df1be1e4ae0223
true true true @shibe_three, @shibe_two

Re-run a draw with no DogeJS code

The whole algorithm with Node's own crypto: the same winners as above. File examples/draw-independent.mjs; run: node examples/draw-independent.mjs.

JavaScript
// Re-run a DogeJS giveaway draw with no DogeJS code at all: Node's own crypto only.
import { createHash } from 'node:crypto';

const sha = (data) => createHash('sha256').update(data).digest();
const seed = '7f3a9c51e2d84b06a1f0c3e5d7b9a2c4e6f8091b3d5f7a9c0e2b4d6f8a1c3e5d';
const ids = ['@shibe_four', '@shibe_one', '@shibe_three', '@shibe_two']; // cleaned: "@" + lower case, de-duplicated
const count = 2;

ids.sort();                                                       // code-unit order
console.log('seed fingerprint', sha(seed).toString('hex'));       // = printf %s SEED | sha256sum
const listHash = sha(ids.join('\n')).toString('hex');
const key = sha(`${seed}\n${listHash}`);

let block = Buffer.alloc(0), pos = 0, counter = 0;
function u32() {                                                  // SHA-256 in counter mode
  if (pos + 4 > block.length) {
    const c = Buffer.alloc(key.length + 4);
    key.copy(c); c.writeUInt32BE(counter++, key.length);
    block = sha(c); pos = 0;
  }
  const v = block.readUInt32BE(pos); pos += 4; return v;
}
function below(n) {                                               // rejection sampling, no modulo bias
  const limit = Math.floor(2 ** 32 / n) * n;
  for (;;) { const v = u32(); if (v < limit) return v % n; }
}
const pool = ids.slice();
for (let i = 0; i < Math.min(count, pool.length); i++) {          // partial Fisher-Yates
  const j = i + below(pool.length - i);
  [pool[i], pool[j]] = [pool[j], pool[i]];
}
console.log('list fingerprint', listHash.slice(0, 16));
console.log('winners:', pool.slice(0, count).join(', '));
Output
seed fingerprint 4793e416d06cf6ce7aa520374bb4d0870f7d0ab7f714bfa2620ed670cb63eacd
list fingerprint f5df1be1e4ae0223
winners: @shibe_three, @shibe_two

A payout file for the winners

When winners are addresses: a CSV for the DogeJS Wallet's Pay many or the command line. The page itself pays nothing. File examples/payout.mjs; run: node examples/payout.mjs.

JavaScript
// Winners that are addresses -> a payout file for the DogeJS Wallet (Pay many) or the dogejs command line.
import { draw, parseDoge, parseEntries, payoutCsv } from '@dogejs/xkit';

const entries = parseEntries('DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L\nnUCAGGgZEPN1QyknmQe1oAku817bQAFKFt\n@shibe_one').entries;
const { winners } = draw('ab'.repeat(32), entries, 3);
const rows = winners.filter((w) => w.kind === 'address').map((w, i) => ({ address: w.id, koinu: parseDoge('25'), label: `giveaway winner ${i + 1}` }));
process.stdout.write(payoutCsv(rows));
Output
address,amount,label
DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L,25,giveaway winner 1
nUCAGGgZEPN1QyknmQe1oAku817bQAFKFt,25,giveaway winner 2

API reference

The exports this page uses. The full list is on the Doge on X developer page.

Fair draw src/draw.ts

ExportReturnsWhat it does
newSeed(rand?)string32 random bytes as 64 hex characters (crypto.getRandomValues).
commitment(seed)stringThe fingerprint to post first: SHA-256 of the 64 hex characters (as printf %s SEED | sha256sum).
revealMatches(seed, commit)booleanDoes a revealed seed match the posted fingerprint?
parseEntries(text){ entries, invalid, duplicates }One entry per line, or every @name and address found in a pasted reply; handles lower-cased with "@"; de-duplicated; sorted.
listFingerprint(entries)stringSHA-256 of the sorted ids joined with "\n".
draw(seed, entries, count){ winners, listHash, commit }Deterministic, order-independent draw (see the algorithm above). At most 100 winners.
verifyDraw({ seed, entries, count, commit?, listPrefix? })DrawCheckRe-runs a draw like a checker and compares the seed and list fingerprints. Never throws. New in 0.2.0.
encodeCheck(seed, count, listHash), decodeCheck(fragment)string; object | nullThe check link fragment c~seed~count~list16.
HashStreamclassSHA-256 counter-mode stream; below(n) gives a uniform integer by rejection sampling.
isSeed, sha256Hex, hex, MAX_ENTRIES, MAX_WINNERSHelpers and limits (10,000 entries, 100 winners).

Payout file src/csv.ts

ExportReturnsWhat it does
payoutCsv(rows)stringaddress,amount,label lines for Pay many and the command line; labels escaped against spreadsheet formulas.
parseDoge(text)bigint | null"25", "2.5" or "2,5" DOGE to koinu (at least 0.01 DOGE).
dogeDecimal(koinu), csvEscape(value)stringPlain decimal DOGE; one escaped CSV field.
CSV_HEADER, MIN_KOINU, MAX_KOINU'address,amount,label', 1000000n, 10 billion DOGE.

Page links and texts src/links.ts

ExportReturnsWhat it does
tipLink(record, base?)stringbase + /x/t/# + fragment; base defaults to https://dogejs.com.
proofLink(record, base?)stringbase + /x/proof/# + fragment.
bioLine(record, base?)stringTips in Dogecoin: dogejs.com/x/t/#..., always without the proof so it stays short.
pinnedPost(), proofPost(handle, address), pricePost(headline, line), wowPost(line), profilePost(), lockPost(commit, entries), winnersPost(winners, commit)stringThe texts the pages prefill in the composer; each stays under 240 with its link.
SITE, PAGES'https://dogejs.com', { hub, tip, tipPage, proof, price, wow, profile, giveaway }The site and the page paths.

Self-hosting

Everything is static files. The page scripts are built from DogeJS-Dev/doge-on-x; the HTML and CSS of the pages are in DogeJS-Dev/website under site/x/.

Shell
git clone https://github.com/DogeJS-Dev/doge-on-x
cd doge-on-x
npm install
npm run build      # dist/x-tip.js, x-t.js, x-proof.js, x-price.js, x-wow.js, x-profile.js, x-giveaway.js
npm test           # unit tests
npm run examples   # runs every example on this page and compares its output
  1. Copy site/x/ from the website repository (the product page of each tool is x/<tool>/, the tool itself x/<tool>/app/), with ui.css, apps.css, styles.css, site.js, pay.js (tip pages) and signin.js (proof page) from the site root, and the images the pages name.
  2. Put the built dist/x-*.js next to the pages as site/x/x-*.js.
  3. Serve the folder from any static host. Nothing else is needed: no database, no keys, no X API.

What changes on your own host: the pages write links for the host they are served from (so your tip links point to your copy), and proofs are signed for your host. A proof page accepts proofs signed for dogejs.com and for its own host, nothing else. To make another host the default for links built in code, pass it as the base argument of tipLink, proofLink and bioLine, and the hosts you accept as allowedHosts of checkProof.