import { createPublicClient, defineChain, http, keccak256, parseAbi, parseAbiItem, toHex } from 'viem';
const robinhood = defineChain({
id: 4663,
name: 'Robinhood Chain',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: { default: { http: ['https://rpc.mainnet.chain.robinhood.com'] } },
});
const client = createPublicClient({ chain: robinhood, transport: http() });
const FACTORY = '0x837cb9F4Ac0d480C95214e2184d3E81427243d15';
const COIN = '0x…';
const abi = parseAbi([
'function vaultOf(address coin) view returns (address)',
'function burned() view returns (uint256)',
'function consumedPostIds(bytes32 postId) view returns (bool)',
'function fallbackBurnsOpenAt() view returns (uint256)',
]);
const fired = parseAbiItem(
'event Fired(address indexed asset, uint256 spent, uint256 bought, uint256 burnedDirect, uint256 gasRefund, uint64 thesisTime, bytes32 thesisId, uint8 kind, address caller)'
);
const vault = await client.readContract({ address: FACTORY, abi, functionName: 'vaultOf', args: [COIN] });
const burned = await client.readContract({ address: COIN, abi, functionName: 'burned' });
// every burn of this coin: tokens burned = bought + burnedDirect
client.watchEvent({
address: vault,
event: fired,
onLogs: (logs) => logs.forEach(({ args }) => console.log(args.kind, args.bought + args.burnedDirect)),
});
// has a fable fired? thesisId = keccak256("native:" + the fable's id); the API's fable record also carries it as thesisId
const THESIS = '…'; // a fable's id (a UUID) from GET /api/theses
const thesisId = keccak256(toHex('native:' + THESIS));
const done = await client.readContract({ address: vault, abi, functionName: 'consumedPostIds', args: [thesisId] });
The example uses Robinhood Chain's public RPC, the one this site adds to your wallet; any RPC endpoint you trust for chain 4663 works.