EVM

Switchboard Randomness for EVM applications

Switchboard On-Demand Randomness provides verifiable, tamper-proof random numbers for EVM smart contracts. This guide covers both the smart contract implementation and the off-chain resolution process.

Use Cases

  • Gaming: Fair loot drops, random encounters, card shuffling

  • NFTs: Random trait generation, blind box reveals

  • DeFi: Random liquidation selection, lottery mechanisms

Prerequisites

  • Basic understanding of Ethereum and smart contracts.

  • Familiarity with common smart contract development tools (e.g., Hardhat, Foundry).

  • A development environment set up and ready to go.

Supported Networks

Network
Chain ID
Switchboard Contract
Block Explorer

Monad Testnet

10143

0xD3860E2C66cBd5c969Fa7343e6912Eff0416bA33

Monad Mainnet

143

0xB7F03eee7B9F56347e32cC71DaD65B303D5a0E67

Hyperliquid Mainnet

999

0xcDb299Cb902D1E39F83F54c7725f54eDDa7F3347

For a complete list of deployments, see EVM Identifiers.

Installation

  1. Solidity SDK:

  2. TypeScript SDK: (For off-chain randomness resolution)

  3. Forge (If applicable): Add the following lines to your remappings.txt file:


Smart Contract Implementation

Step 1: Contract Setup (Solidity)

  1. Import Switchboard Interfaces:

  2. Implementation:

Note that one has to inject the address of the Switchboard contract on deployment and select the appropriate network for the queue. For reference, the latest deployments can be found in EVM Identifiers.

Step 2: Request Randomness

Call the requestRandomness function within your smart contract:

randomnessId has to be unique for tracking your request. Then inject it into your chain-appropriate queue using the deployed Switchboard's address and requestRandomness function.

IMPORTANT: Ensure sufficient delay time for randomness to be resolved by oracles! The minimum settlement delay must pass and the request data must propagate on-chain.

Step 3: Setup Update Feed Handler

Given all the correct parameters, you are now able to call into the Switchboard oracle to resolve your randomness.


Off-Chain Resolution (TypeScript)

Complete Working Example

This example demonstrates the full randomness flow from request to settlement:

Step-by-Step Flow

1. Create Randomness Request

2. Wait for Settlement Delay

3. Fetch Randomness Reveal from Crossbar

4. Settle Randomness On-Chain

5. Read and Use the Random Value


Simple Resolution Example

For a simpler approach using an existing contract with randomnessId exposed:


Integration Tips

  • Use the raw 256-bit value for maximum entropy

  • Apply modulo for bounded ranges: value % range

  • For multiple random values, hash the result with different salts

  • Store randomnessId to verify the result matches your request

  • Always add a buffer (5-10 seconds) to the settlement delay for clock skew

Summary

Integrate Switchboard randomness to get secure, verifiable randomness in your EVM smart contracts. The flow is:

  1. Create a randomness request on-chain

  2. Wait for the settlement delay

  3. Fetch the randomness reveal from Crossbar

  4. Settle the randomness on-chain

  5. Read and use the verified random value

You've now implemented a secure and verifiable way to get randomness in your EVM smart contracts!

Last updated