SDK
Official TypeScript SDK and Solidity interfaces for Torinox Protocol.
Installation
npm install @diceprotocol/sdkPublished on npm as @diceprotocol/sdk. Apache-2.0. Interfaces adapted from Pyth Entropy; not a Pyth-operated service.
Solidity Interfaces
Install the package, then import the Solidity interfaces from the published GitHub repo into your project.
import { IEntropyConsumer } from "@diceprotocol/sdk/solidity/IEntropyConsumer.sol";
import { IEntropy } from "@diceprotocol/sdk/solidity/IEntropy.sol";
contract MyGame is IEntropyConsumer {
IEntropy public immutable dice;
address public provider = 0x8741b8a825644D9Ef18Faf2DAB5e9b47B900F2b6;
constructor(address _dice) {
dice = IEntropy(_dice);
}
function roll(bytes32 userRandom) external payable {
// Generate userRandom client-side with a CSPRNG and keep it private.
dice.requestV2{value: msg.value}(
provider, userRandom, 200000
);
}
function entropyCallback(uint64 seq, address, bytes32 random)
internal override {
// Use random number - it's verifiable onchain
}
function getEntropy() internal view override returns (address) {
return address(dice);
}
}TypeScript SDK
import { TorinoxProtocol } from '@diceprotocol/sdk';
import { ethers, JsonRpcProvider, Wallet } from 'ethers';
const rpcUrl = 'https://rpc.mainnet.chain.robinhood.com';
const signer = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(rpcUrl));
const dice = new TorinoxProtocol({
rpcUrl,
contractAddress: '0xd8a0680e7699526b57140ed4eafdcc7219dc0a0c',
});
// Equivalent helper form:
// const fee = await dice.getFee('0x8741b8a825644D9Ef18Faf2DAB5e9b47B900F2b6', 200000);
// const userRandom = TorinoxProtocol.generateUserRandom();
// Get current fee
const fee = await dice.getFee(
'0x8741b8a825644D9Ef18Faf2DAB5e9b47B900F2b6'
);
// Request randomness (agent provides its own random contribution)
const userRandom = ethers.hexlify(ethers.randomBytes(32));
const seqNum = await dice.requestRandom(
signer,
'0x8741b8a825644D9Ef18Faf2DAB5e9b47B900F2b6',
userRandom,
200000
);
// If not revealed in ~60-90s: dice.refundRequest(signer, provider, seq)
// Listen for reveal (~1-3 seconds typical)
dice.onReveal((event) => {
if (event.sequence === seqNum) {
console.log('Random number:', event.randomNumber);
}
});Agent Integration
Torinox Protocol is designed to be developer-ready - any AI agent, automation bot, or orchestration system can request randomness with zero human intervention. The contract is immutable, fees are deterministic, and the keeper reveals automatically.
x402 (USDG) + stake credits - live
POST https://diceprotocol.world/x402/v1/random · fixed $0.05 USDG · Primer · Robinhood Chain · gateway sponsors v10 ETH fee.
Info: GET /x402/v1/info · Health: GET /x402/health
A complete SDK repository is published in the SDK repo - agents can read it and integrate without any human help.
Why it is reliable:
getFee() always returns current cost. No surprises.Package source: github.com/diceprotocol/dice-protocol-sdk