Wildcard Off-Chain Reactivity Tutorial
Subscribe to all new logs over WebSocket and receive optional read-only call results with each event
Prerequisites
npm install @somnia-chain/reactivity viem
npm install --save-dev tsx typescript @types/nodeStep 1: Define the Chain
import { defineChain } from 'viem';
const somniaTestnet = defineChain({
id: 50312,
name: 'Somnia Testnet',
nativeCurrency: {
decimals: 18,
name: 'STT',
symbol: 'STT',
},
rpcUrls: {
default: {
http: ['https://api.infra.testnet.somnia.network'],
webSocket: ['wss://api.infra.testnet.somnia.network/ws'],
},
},
});Step 2: Create the SDK
Step 3: Subscribe to All Logs
Field
Meaning
Step 4: Decode a Known Event
Full Script
Next Steps
Last updated