READ Stream Data from a UI (Next.js Example)
Prerequisites
npm i @somnia-chain/streams viemSet up the SDK and Client
// lib/store.ts
import { SDK } from '@somnia-chain/streams'
import { createPublicClient, http } from 'viem'
import { somniaTestnet } from 'viem/chains'
const publicClient = createPublicClient({
chain: somniaTestnet,
transport: http(),
})
export const sdk = new SDK(publicClient)Define Schema and Publisher
Fetch Latest “Hello World” Message
Fetch by Key (e.g., message ID)
Fetch by Index (Sequential Logs)
Fetch a Range of Records (Paginated View)
Fetch All Publisher Data for a Schema
Count Total Entries
Inspect Schema Metadata
Retrieve Full Schema Information
Example Next.js App
Project Setup
Folder Structure
lib/store.ts
lib/schema.ts
lib/read.ts
app/api/latest/route.ts
components/StreamViewer.tsx
components/SchemaInfo.tsx
app/page.tsx
app/layout.tsx
Run the App
Summary Table
Method
Purpose
Example
Last updated