RandomMaterial

Storage Plain v101 → v411

Ring buffer of the last 81 block hashes used as random seed material.

Explore chain
Queried by: developersvalidators

The Big Picture

This is Substrate's legacy randomness solution. It collects block hashes as a ring buffer and uses them as random seed material. While simple, it's somewhat predictable (block producers know future hashes) and is being replaced by more secure randomness sources like Drand in modern Bittensor.

Why This Matters

On-chain randomness is tricky. This pallet provides a simple solution using block hashes, but it's predictable by block producers. For most casual uses it's fine, but security-critical randomness should use Drand or commit-reveal schemes.

Example Scenario

A subnet needs to randomly select a validator for a task. It queries RandomMaterial to get the seed, then hashes it with some unique input to produce a pseudo-random selection. The result is deterministic but hard to predict for users who don't produce blocks.

Common Questions

Why 81 blocks?
A somewhat arbitrary choice that provides a buffer of recent hashes. 81 blocks (~16 minutes) gives variety while keeping storage bounded.
Is this secure for lotteries?
Not really. Block producers can manipulate the random seed by choosing which block to produce. For high-stakes randomness, use Drand or commit-reveal patterns.
Why is this called 'CollectiveFlip'?
Historical naming from early Substrate. 'Collective' because all validators contribute hashes, 'Flip' as in coin flip for randomness. The name stuck even though it's legacy.

Use Cases

  • Generate pseudo-random values for on-chain logic
  • Seed lottery or selection mechanisms
  • Provide unpredictable values for game mechanics

From Chain Metadata

Series of block headers from the last 81 blocks that acts as random seed material. This is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of the oldest hash.

Purpose & Usage

Purpose

Provides on-chain randomness derived from recent block headers.

Common Query Patterns

  • Query for current random seed material
  • Used internally by pallets needing randomness

Notes

  • Ring buffer indexed by block_number % 81
  • Oldest hash is at current index, newest is at index-1
  • Not cryptographically secure - block producers can influence
  • Legacy pallet - prefer Drand for new applications

Stored Value

value (BoundedVec)

Code Examples

import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443

const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);

// Query RandomMaterial storage (no keys - plain value)
const result = await api.query.RandomnessCollectiveFlip.RandomMaterial.getValue();
console.log("RandomMaterial:", result);

Version History

v101 block 1 Added
v120 block 315,568 Internal re-bind
v123 block 720,235 Internal re-bind
v128–v132 · runtime versions skipped on chain (never deployed)
v133 block 1,404,224 Internal re-bind
v136 block 1,756,781 Internal re-bind
v138 block 1,907,363 Internal re-bind
v140 block 1,929,216 Internal re-bind
v149 block 3,014,339 Internal re-bind
v154 block 3,308,611 Internal re-bind
v166–v194 · runtime versions skipped on chain (never deployed)
v195 block 3,791,350 Internal re-bind
v207–v209 · runtime versions skipped on chain (never deployed)
v210 block 4,345,556 Internal re-bind
v213–v215 · runtime versions skipped on chain (never deployed)
v216 block 4,510,996 Internal re-bind
v235–v237 · runtime versions skipped on chain (never deployed)
v238 block 4,936,550 Internal re-bind
v266–v272 · runtime versions skipped on chain (never deployed)
v273 block 5,659,032 Internal re-bind
v278–v289 · runtime versions skipped on chain (never deployed)
v290 block 5,947,548 Internal re-bind
v307–v314 · runtime versions skipped on chain (never deployed)
v315 block 6,414,634 Internal re-bind
v316–v319 · runtime versions skipped on chain (never deployed)
v320 block 6,523,566 Internal re-bind
v327–v333 · runtime versions skipped on chain (never deployed)
v334 block 6,811,690 Internal re-bind
v353–v360 · runtime versions skipped on chain (never deployed)
v361 block 7,063,679 Internal re-bind
v386–v390 · runtime versions skipped on chain (never deployed)
v391 block 7,782,857 Internal re-bind
v394–v400 · runtime versions skipped on chain (never deployed)
v401 block 8,036,576 Internal re-bind Current

Runtime Info

Pallet
RandomnessCollectiveFlip
Storage Kind
Plain
First Version
v101
Current Version
v411