@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / reactivity / createReactivity

Function: createReactivity()

createReactivity(client, opts?): SDK

Defined in: packages/sdk/src/reactivity/index.ts:177

Build a reactivity client on the markets client's own WebSocket — the socket is already open and already pointed at the right node, and watch needs a WebSocket transport.

ts
import { SomniaMarkets } from "@somnia-chain/markets-sdk";
import { createReactivity, unwrap } from "@somnia-chain/markets-sdk/reactivity";
import { somniaShannon } from "@somnia-chain/markets-sdk/chains";

const exchange = new SomniaMarkets({ chain: somniaShannon, wsRpcUrl, indexerUrl });
const reactivity = createReactivity(exchange.client);

// Every Transfer on the collateral token, with the sender's new balance read
// at the very same block — one notification, no follow-up call.
const watch = unwrap(
  await reactivity.watch({
    eventContractSources: [collateral],
    topicOverrides: [transferTopic],
    ethCalls: [{ to: collateral, data: balanceOfCalldata }],
    onData: (n: ReactivityNotification) => console.log(n.result.simulationResults),
  }),
);
await watch.unsubscribe();

Parameters

client

Pick<SomniaMarketsClient, "getViemClient">

The markets client (exchange.client) whose public client to use.

opts?

CreateReactivityOptions = {}

Optional wallet client for the write methods.

Returns

SDK

An upstream SDK instance — the full reactivity surface.