Prerequisites: You need a Risk API key, a
Solana development environment (Anchor or Pinocchio), and familiarity with
Switchboard On-Demand Oracles.
How It Works
The Onchain Risk Verifier uses Switchboard On-Demand Oracles to fetch signed risk data from Range’s Risk API and verify it inside your Solana program. No persistent data feeds are required - quotes are requested on demand.Security Model
- Tamper-proof: The program reconstructs the exact same feed definition onchain and hashes it. Any change to the URL, headers, or processing tasks changes the hash, causing verification to fail.
- Cryptographic verification: Switchboard oracles run in Trusted Execution Environments (TEEs) and sign results with Ed25519. The program verifies these signatures Onchain.
- Freshness checks: The program rejects quotes older than a configurable number of slots (e.g., 50 slots ≈ 20 seconds).
- API keys stay off-chain: Range API keys are injected as variable overrides at the oracle level - they never appear Onchain.
Use Cases
| Scenario | How ORV Helps |
|---|---|
| Privacy protocols | Screen deposits to prevent illicit funds from entering the pool |
| Lending protocols | Reject deposits or borrows from high-risk wallets |
| Treasury management | Gate payouts to wallets below a risk threshold |
| Governance | Only allow proposals or votes from verified-clean addresses |
| Bridges | Block transfers involving sanctioned or malicious addresses |
| DEX / AMM | Warn or block swaps with flagged counterparties |
Step 1: Define the Oracle Job (TypeScript)
The Oracle Job tells Switchboard what data to fetch and how to process it. This job calls Range’s Address Risk Score endpoint, parses theriskScore, scales it to 0–100, and bounds the result.
The
${RANGE_API_KEY} placeholder is resolved by the Switchboard oracle at
runtime using variable overrides. Your API key is never exposed onchain or in
transaction data.Step 2: Request a Signed Quote (TypeScript)
Use the Switchboard SDK to request a signed quote and build the Ed25519 verification instruction.Step 3: Build and Send the Transaction (TypeScript)
Combine the signature verification instruction with your program instruction in a single transaction.The Switchboard SDK (
@switchboard-xyz/on-demand) uses @solana/web3.js types internally.
The transaction building code below uses web3.js for compatibility with the SDK.Step 4: Verify Onchain (Rust)
The Solana program reconstructs the same feed definition, hashes it, and compares against the oracle quote to ensure data integrity.Step 5: Run the Example
Range provides a complete working example with both Anchor and Pinocchio implementations.The test requires a funded Solana devnet wallet. If you don’t have one,
generate a keypair with
solana-keygen new -o keypair.json and airdrop devnet
SOL with solana airdrop 2 --keypair keypair.json --url devnet.Customizing for Your Program
Adjusting the Risk Threshold
Modify the onchain program to enforce your risk policy:Checking Different Networks
Update the URL in both the TypeScript OracleJob and the Rust feed reconstruction to query different networks:Production Considerations
- Increase
numSignatures- Use more than 1 signature for production to increase consensus requirements. - Tune staleness - The example uses 50 slots (~20 seconds). Tighten this for time-sensitive operations.
- Use mainnet queue - Switch from
getDefaultDevnetQueuetogetDefaultQueuefor production deployments. - Handle errors gracefully - Decide whether a failed risk check should block the transaction or allow it with a warning flag.
Cross-Chain Support
The Onchain Risk Verifier is currently implemented for Solana. The same architecture could be adapted for EVM (Solidity) and CosmWasm smart contracts — the core pattern of oracle-fetched signed data with onchain signature and feed integrity verification is framework-agnostic. If you’re interested in an EVM or CosmWasm implementation, get in touch.What’s Next
Address Risk Score
Full endpoint reference for the Risk API endpoint used by the oracle job.
Switchboard Docs
Switchboard On-Demand Oracle documentation and SDK reference.
Example Repository
Complete working implementation with Anchor and Pinocchio frameworks.
Wallet Integration
For off-chain risk screening in wallets and dApps.

