TypeScript SDK
For apps and back ends. @nightcast/sdk turns one answer into any kind of choice, and runs an oracle or checks one.
Nightcast Developers
Ask Midnight for a random value. It comes back with a proof, and the SDK turns it into winners, shuffles, dice or prizes that anyone can check for themselves.
npm install @nightcast/sdk @nightcast/contract import { listCommitment, pickMany } from '@nightcast/sdk';
const entrants = ['Ava', 'Ben', 'Chloe', 'Dev', 'Ella'];
// Seal the list: its fingerprint is the request's seed.
// Publish it first, so the list can't change later.
const seed = listCommitment(entrants);
// Once Nightcast answers, the same output gives
// the same winners on any computer.
const winners = pickMany(output, entrants, 2);
import { findDeployedContract }
from '@midnight-ntwrk/midnight-js/contracts';
const nightcast = await findDeployedContract(providers, {
contractAddress, // the published deployment
compiledContract, // from @nightcast/contract
privateStateId: 'nightcast',
initialPrivateState: { requesterSecret },
});
// 30 minutes to answer, or the fee goes to refundTo.
const now = Math.floor(Date.now() / 1000);
const deadline = BigInt(now + 30 * 60);
const sent = await nightcast.callTx.request(
tag, seed, deadline, { bytes: refundTo },
);
const id = sent.private.result;
import { ledger, Status } from '@nightcast/contract';
// The answer is public: read it from an indexer.
const state = await publicDataProvider
.queryContractState(contractAddress);
const r = ledger(state!.data).requests.lookup(id);
if (r.status === Status.fulfilled) {
// 32 bytes. The network checked the oracle's
// proof before storing them: nothing to verify.
const output = r.output;
}
// Claude desktop, Claude Code or Cursor:
{
"mcpServers": {
"nightcast": {
"command": "/path/to/Nightcast/nightcast",
"args": ["mcp", "--network", "preprod"]
}
}
}
// Read-only as shown: add a wallet to make requests.
// The agent then has five tools:
// nightcast_list_fingerprint, nightcast_request_random,
// nightcast_check_request, nightcast_derive, nightcast_about
Fix the entrants, prizes and rules first, and put their fingerprint in the request as its seed.
One transaction on the Nightcast contract, with a deadline and an address for a refund.
Its answer is a zero-knowledge proof: Midnight's validators accept only the one value its key allows.
Turn the 32 bytes into your result. Anyone with the same inputs gets the same answer.
If the deadline passes without an answer, anyone can expire the request, and the fee and the oracle's collateral go to your refund address. Decide in advance what happens then: usually, announce a new draw. Never ask again until the result looks right.
For apps and back ends. @nightcast/sdk turns one answer into any kind of choice, and runs an oracle or checks one.
An MCP server with five tools: fingerprint a list, request, check, derive and explain. A draw with no person in the loop, that people can still audit.
Set up the MCP serverFor randomness in a circuit. Today a contract embeds the same VRF, as Lunardraw's Starfall does, and the NightcastWords module turns its output into words.
In the Quinelings ranch, one 32-bit number decides what two creatures' child looks like, so whoever picks it can keep trying. This demo seals each pair first, then lets Nightcast draw the number on Midnight Preprod. Three real breedings, each checkable in your browser.
An independent demonstration using the open-source Quinelings, by Charles Hoskinson. Not made or endorsed by the Quinelings project.
Every function takes the 32-byte answer and gives the same result on every computer, so the people your draw affects can repeat it.
Batches are new: many numbers from one request, each with a receipt. The SDK part is on GitHub and comes to npm in the next release; the service that answers them is being built.
| Function | Gives you |
|---|---|
pickMany(output, items, k) | k different winners, in the order drawn. |
pick(output, items) | One item from a list. |
shuffle(output, items) | The whole list in a fair order. |
randomInt(output, min, max) | A whole number in a range, with no bias. |
rollDice(output, count, sides) | Dice, six-sided unless you say. |
weightedPick(output, weights) | A prize table: rarer prizes come up less often. |
listCommitment(items) | A list's fingerprint, to seal it before the draw. |
randomWords(output, n) | Many independent 32-byte words from one answer. |
sealBatch, makeReceipt, checkReceipt | Many numbers from one request, each with its own receipt. On GitHub now; in the next npm release. |
Both contracts are locked: nobody, including us, can change their code after deployment.
eaae909ead…b044a73adb Answers LunaSpin's spins.
46d0489c7d…4e999b1ead A test deployment for measuring real proofs and fees: short epochs and test pool keys. It will be replaced. See it running
The full records, with verifier keys and transaction ids: deployments on GitHub.
Use Nightcast for results everyone should see, like winners and dice. It isn't for secrets, such as a hand of cards that must stay hidden.
It can't choose a value, but it can fail to answer. Every request has a deadline and a refund, and the threshold network fines seats that miss.
Anything decided after the value is known can be steered. Seal lists and rules in the request's seed.
Build and test on Preprod now. Mainnet follows an independent security audit.
Tell us what you're making. We'll help you wire it up on Preprod, and you'll be first to hear when Mainnet opens.
We only use your email for Nightcast early access. We don't share it. Privacy