Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 1.93 KB

README.md

File metadata and controls

68 lines (51 loc) · 1.93 KB

Stateless Viem Transport

This is a custom transport for viem that allows you to use Stateless' verifiable RPC endpoints.

Installation

npm install stateless-viem-transport

Usage

import { createPublicClient, custom } from "viem";
import { mainnet } from "viem/chains";
import { createStatelessTransport } from "stateless-viem-transport";

const statelessTransport = createStatelessTransport({
  rpcUrl: "https://api.stateless.solutions/ethereum/v1/<YOUR_BUCKET_ID>",
  identities: ["https://<PROVIDER_IDENTITY>"],
});

const statelessClient = createPublicClient({
  chain: mainnet,
  transport: custom(statelessTransport),
});

console.log("Block Number:", await statelessClient.getBlockNumber());

Light Clients

To use Stateless' light client mode, you can add an additional proverUrl parameter. This will enable the light client mode, which will verify the stateless proofs on the prover node.

Read more about the light client mode in the Stateless docs.

import { createStatelessTransport } from "stateless-viem-transport";

const statelessTransport = createStatelessTransport({
  rpcUrl: "https://<PROVIDER_RPC_URL>",
  identities: ["https://<PROVIDER_IDENTITY>"],
  proverUrl: "https://<PROVER_RPC_URL>", // enables light client mode
});

const statelessClient = createPublicClient({
  chain: mainnet,
  transport: custom(statelessTransport),
});

const contractAbi = [
  {
    inputs: [],
    name: "totalSupply",
    outputs: [{ type: "uint256" }],
    stateMutability: "view",
    type: "function",
  },
] as const;

const contract = getContract({
  address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  abi: contractAbi,
  client: statelessClient,
});

console.log("USDC Total supply:", await contract.read.totalSupply());