Skip to content

HTTP Transport

The http Transport connects to a JSON-RPC API via HTTP.

Import

import { http } from "cive";

Usage

import { http, createPublicClient } from 'cive'
import { mainnet } from 'cive/chains'
 
const client = createPublicClient({
  chain: mainnet,
  transport: http("https://main.confluxrpc.com/..."),
});

Batch JSON-RPC

The http Transport supports Batch JSON-RPC. This means that multiple JSON-RPC requests can be sent in a single HTTP request.

The Transport will batch up Actions over a given period and execute them in a single Batch JSON-RPC HTTP request. By default, this period is a zero delay meaning that the batch request will be executed at the end of the current JavaScript message queue. Consumers can specify a custom time period wait (in ms).

You can enable Batch JSON-RPC by setting the batch flag to true:

import { http } from "cive";
const transport = http("https://main.confluxrpc.com/...", {
  batch: true, 
});

Now when you invoke Actions, the http Transport will batch and send over those requests at the end of the message queue (or custom time period) in a single Batch JSON-RPC HTTP request:

import { http, createPublicClient } from 'cive'
import { mainnet } from 'cive/chains'
const client = createPublicClient({
  chain: mainnet,
  transport: http("https://main.confluxrpc.com/..."),
});
// ---cut---
// The below will send a single Batch JSON-RPC HTTP request to the RPC Provider.
const [blcok, balance, status] = await Promise.all([
  client.getBlock(),
  client.getBalance({ address: "cfx:..." }),
  client.getStatus(),
]);

Parameters

The http is a re-export of the viem, So you can refer to Viem for information on the parameters.