Skip to content

Custom Transport

The custom Transport accepts an request function as a parameter, This transport is useful for integrating with injected wallets. or even providing your own custom request function.

Import

import { custom } from "cive";

Usage

import { createWalletClient, custom } from "cive";
import { mainnet } from "cive/chains";
 
const client = createWalletClient({
  chain: mainnet,
  transport: custom(window.fluent!),
});

Or you can define your own:

import { createWalletClient, custom } from "cive";
import { mainnet } from "cive/chains";
 
const client = createWalletClient({
  chain: mainnet,
  transport: custom({
    async request({ method, params }) {
      const response = await fetch("https:/...");
      return response;
    },
  }),
});

Parameters

provider

  • Type: custom
import { createWalletClient, custom } from "cive";
import { mainnet } from "cive/chains";
 
const client = createWalletClient({
  chain: mainnet,
  transport: custom({
    async request({ method, params }) {
      const response = await fetch("https:/...");
      return response;
    },
  }),
});

key (optional)

  • Type: string
  • Default: "custom"

A key for the Transport.

const transport = custom(window.fluent!, {
  key: "windowProvider", 
});

name (optional)

  • Type: string
  • Default: "Provider"

A name for the Transport

const transport = custom(window.fluent!, {
  name: "Window  Provider", 
});

retryCount (optional)

  • Type: number
  • Default: 3

The max number of times to retry when a request fails.

const transport = custom(window.fluent!, {
  retryCount: 5, 
});

retryDelay (optional)

  • Type: number
  • Default: 150

The base delay (in ms) between retries. By default, the Transport will use exponential backoff (~~(1 << count) * retryDelay), which means the time between retries is not constant.

const transport = custom(window.fluent!, {
  retryDelay: 100, 
});

Gotchas