Skip to content

ABIs and TypeScript

/randoo.json is the machine-readable source for every network: chain ID, RPC, explorer, coordinator address, oracle key hash and status. It also carries the Ronin-interface ABIs, under abi.coordinator (requestRandomSeed, estimateRequestRandomFee, minRequestGasPrice, seedOf), abi.consumer (rawFulfillRandomSeed) and abi.events (RandomSeedRequested, RandomSeedFulfilled). For the Chainlink wrapper interface, use Chainlink's own ABIs.

The TypeScript SDK, @randoo/sdk, is not published yet. Until it is, call the coordinator with viem or any other Ethereum library.

Quote a fee

quote.ts
import { createPublicClient, http, parseAbi } from "viem";

const coordinator = "0xC66eB2e7EE91145875000Ad46B55600000000001"; // the same on every network
const client = createPublicClient({ transport: http("https://base-rpc.publicnode.com") });

const coordinatorAbi = parseAbi([
  "function estimateRequestRandomFee(uint256 callbackGasLimit, uint256 gasPrice) view returns (uint256)",
]);

// Base and Robinhood: the network gas price.
// Ronin and Saigon: 23 gwei instead (see Fees and failures).
const gasPrice = await client.getGasPrice();

const fee = await client.readContract({
  address: coordinator,
  abi: coordinatorAbi,
  functionName: "estimateRequestRandomFee",
  args: [250_000n, gasPrice],
});
// Send at least `fee` as msg.value with the request. The excess comes back after fulfillment.

Only your consumer contract can call requestRandomSeed, so the request goes through your consumer's own payable function, such as roll in the Quickstart template.

Read a result

The request transaction emits RandomSeedRequested from the coordinator. Its reqHash identifies the request. Once the oracle fulfills, seedOf returns the seed, even if your callback reverted.

result.ts
import { createPublicClient, http, parseAbi, parseEventLogs, type Hash } from "viem";

const coordinator = "0xC66eB2e7EE91145875000Ad46B55600000000001";
const client = createPublicClient({ transport: http("https://base-rpc.publicnode.com") });

const coordinatorAbi = parseAbi([
  "event RandomSeedRequested(bytes32 indexed reqHash, uint256 indexed requestId, address indexed consumer, uint256 callbackGasLimit, uint256 gasPrice, address refundAddress, uint256 prepaid)",
  "function seedOf(bytes32 reqHash) view returns (uint256 seed, bool fulfilled, bool callbackOk)",
]);

export async function resultOf(requestTx: Hash) {
  const receipt = await client.getTransactionReceipt({ hash: requestTx });
  const [requested] = parseEventLogs({
    abi: coordinatorAbi,
    eventName: "RandomSeedRequested",
    logs: receipt.logs,
  });
  const [seed, fulfilled, callbackOk] = await client.readContract({
    address: coordinator,
    abi: coordinatorAbi,
    functionName: "seedOf",
    args: [requested.args.reqHash],
  });
  return { reqHash: requested.args.reqHash, seed, fulfilled, callbackOk };
}

Updated 2026-11-11.