Appearance
Requesting randomness
Inherit VerityConsumerBase, add your contract as a consumer of a funded subscription, then call:
solidity
uint256 requestId = s_coordinator.requestRandomWords(
keyHash, // which oracle key (gas lane) proves the result
subId, // which subscription pays
minimumRequestConfirmations, // blocks to wait before proving: 3..200
callbackGasLimit, // gas for your fulfillRandomWords
numWords // 1..500 words
);| Parameter | Guidance |
|---|---|
keyHash | A lane from Networks. The lane caps the gas price you can be charged. |
minimumRequestConfirmations | More confirmations means more protection against chain reorganisations, but slower results. PulseChain blocks take ~10 s; 3 is the minimum. Use more for high-value draws. |
callbackGasLimit | Measure your callback's gas and add a margin. Too little means the callback reverts out of gas, and that fulfilment is final. You pay for the reservation, not the limit, so don't wildly oversize it. |
numWords | Each word is an independent uint256. One word is often enough: slice it, or derive more with keccak256(abi.encode(word, i)). |
What happens next
- The
RandomWordsRequestedevent is emitted; the request is pending. - After
minimumRequestConfirmationsblocks, the oracle node proves the result againstkeccak256(preSeed, blockhash(requestBlock)). - The coordinator verifies the proof and calls
rawFulfillRandomWordson your contract with exactlycallbackGasLimitgas. - Words are
uint256(keccak256(abi.encode(randomness, i)))fori = 0..numWords-1. Anyone can recompute them from theRandomWordsFulfilledevent.
On PulseChain testnet this takes about 45 seconds end to end.
Request ids
requestId = keccak256(abi.encode(keyHash, keccak256(abi.encode(coordinator, keyHash, consumer, subId, nonce)))), where coordinator is the coordinator's own address and nonce counts your consumer's requests. computeRequestId(coordinator, keyHash, consumer, subId, nonce) in the SDK reproduces it off-chain.
Because the coordinator address is part of the seed, request ids do not repeat across coordinators, even after a subscription migration restarts your consumer's nonce on a new coordinator.
Timeouts and cancellation
If no proof arrives within the coordinator's requestTimeoutBlocks (8,640 blocks ≈ 24 h on testnet), the consumer or the subscription owner can call cancelRequest(requestId, commitment) (or verity request cancel --request-id <id>) to release the reservation. Cancellation is a refund, not a reroll. Read the security rules.
Requests older than 256 blocks remain fulfillable: the oracle stores their block hash in the BlockhashStore before it leaves the EVM's window.