Skip to content

watchClient

Action for watching changes to the Starknet client configuration.

Import

import { watchClient } from "starkweb/core";

Usage

index.ts
import { watchClient } from "starkweb/core";
import { config } from "./config";
 
const unwatch = watchClient(config, {
  onChange(client, prevClient) { 
    console.log('Client changed:', client); 
    console.log('Previous client:', prevClient); 
  }, 
});

Parameters

import { type WatchClientParameters } from "starkweb/core";

onChange

(client: GetClientReturnType, prevClient: GetClientReturnType) => void

Callback function that is called when the client configuration changes. Receives the new client and previous client as arguments.

index.ts
import { watchClient } from "starkweb/core";
import { config } from "./config";
 
const unwatch = watchClient(config, {
  onChange(client, prevClient) { 
    console.log('Client changed:', client); 
    console.log('Previous client:', prevClient); 
  }, 
});

Return Type

import { type WatchClientReturnType } from "starkweb/core";

() => void

Function to stop watching for client changes.

Example

example.ts
import { watchClient } from "starkweb/core";
import { config } from "./config";
 
// Start watching client changes
const unwatch = watchClient(config, {
  onChange(client, prevClient) { 
    if (client.uid !== prevClient.uid) {
      console.log('Client instance changed');
    }
    if (client.chain.id !== prevClient.chain.id) {
      console.log('Client chain changed');
    }
  }, 
});
 
// Later: stop watching
unwatch();