npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@trezoa/rpc

v5.1.0

Published

A library for sending JSON RPC requests to Trezoa RPCs

Readme

npm npm-downloads code-style-prettier

@trezoa/rpc

This package contains utilities for creating objects that you can use to communicate with a Trezoa JSON RPC server. It can be used standalone, but it is also exported as part of Kit @trezoa/kit.

Unless you plan to create a custom RPC interface, you can use the createTrezoaRpc(clusterUrl) function to obtain a default implementation of the Trezoa JSON RPC API.

Types

RpcTransport{Devnet|Testnet|Mainnet}

These types refine the base RpcTransport type. Each describes a transport that is specific in some way to a particular Trezoa cluster.

For instance, a RpcTransportDevnet is understood to communicate with a RPC server related to devnet, and as such might only be accepted for use as the transport of a RpcDevnet.

This is useful in cases where you need to make assertions about what capabilities a RPC offers. For example, RPC methods like requestAirdrop are not available on mainnet. You can use the ability to assert on the type of RPC transport at compile time to prevent calling unimplemented methods or presuming the existence of unavailable capabilities.

RpcTransportFromClusterUrl<TClusterUrl extends ClusterUrl>

Given a ClusterUrl, this utility type will resolve to as specific a RpcTransport as possible.

function createCustomTransport<TClusterUrl extends ClusterUrl>(
    clusterUrl: TClusterUrl,
): RpcTransportFromClusterUrl<TClusterUrl> {
    /* ... */
}
const transport = createCustomTransport(testnet('http://api.testnet.trezoa.com'));
transport satisfies RpcTransportTestnet; // OK

Rpc{Devnet|Testnet|Mainnet}<TRpcMethods>

These types refine the base Rpc type. Each describes a RPC that is specific in some way to a particular Trezoa cluster and a corpus of RPC methods.

This is useful in cases where you need to make assertions about the suitability of a RPC for a given purpose. For example, you might like to make it a type error to combine certain types with RPCs belonging to certain clusters, at compile time.

async function getSpecialAccountInfo(
    address: Address<'ReAL1111111111111111111111111111'>,
    rpc: RpcMainnet<unknown>,
): Promise<SpecialAccountInfo>;
async function getSpecialAccountInfo(
    address: Address<'TeST1111111111111111111111111111'>,
    rpc: RpcDevnet<unknown> | RpcTestnet<unknown>,
): Promise<SpecialAccountInfo>;
async function getSpecialAccountInfo(address: Address, rpc: Rpc<unknown>): Promise<SpecialAccountInfo> {
    /* ... */
}
const rpc = createTrezoaRpc(devnet('https://api.devnet.trezoa.com'));
await getSpecialAccountInfo(address('ReAL1111111111111111111111111111'), rpc); // ERROR

RpcFromTransport<TRpcMethods, TRpcTransport extends RpcTransport>

Given a RpcTransport and a set of RPC methods denoted by TRpcMethods this utility type will resolve to a Rpc that supports those methods on as specific a cluster as possible.

function createCustomRpc<TRpcTransport extends RpcTransport>(
    transport: TRpcTransport,
): RpcFromTransport<MyCustomRpcMethods, TRpcTransport> {
    /* ... */
}
const transport = createDefaultRpcTransport({ url: mainnet('http://rpc.company') });
transport satisfies RpcTransportMainnet; // OK
const rpc = createCustomRpc(transport);
rpc satisfies RpcMainnet<MyCustomRpcMethods>; // OK

TrezoaRpcApiFromTransport

Given a RpcTransport this utility type will resolve to a union of all the methods of the Trezoa RPC API supported by the transport's cluster.

function createTrezoaRpcFromTransport<TTransport extends RpcTransport>(
    transport: TTransport,
): RpcFromTransport<TrezoaRpcApiFromTransport<TTransport>, TTransport> {
    /* ... */
}
const transport = createDefaultRpcTransport({ url: mainnet('http://rpc.company') });
transport satisfies RpcTransportMainnet; // OK
const rpc = createTrezoaRpcFromTransport(transport);
rpc satisfies RpcMainnet<TrezoaRpcApiMainnet>; // OK

Constants

DEFAULT_RPC_CONFIG

When you create Rpc instances with custom transports but otherwise the default RPC API behaviours, use this.

const myCustomRpc = createRpc({
    api: createTrezoaRpcApi(DEFAULT_RPC_CONFIG),
    transport: myCustomTransport,
});

Functions

createDefaultRpcTransport(config)

Creates a RpcTransport with some default behaviours.

The default behaviours include:

  • An automatically-set Trezoa-Client request header, containing the version of @trezoa/kit
  • Logic that coalesces multiple calls in the same runloop, for the same methods with the same arguments, into a single network request.
  • [node-only] An automatically-set Accept-Encoding request header asking the server to compress responses

Arguments

A config object with the following properties:

  • dispatcher_NODE_ONLY: An optional Undici.Dispatcher instance that governs how the networking stack should behave. This option is only relevant in Node applications. Consult the documentation for the various subclasses of Undici.Dispatcher, such as Agent, Client, and Pool, at https://undici.nodejs.org/#/docs/api/Client.
  • headers: An optional object where the keys are HTTP header names and the values are HTTP header values. This parameter is typed to disallow certain headers from being overwritten.
  • url: A ClusterUrl at which the RPC server can be contacted.

createTrezoaRpc(clusterUrl, config)

Creates a Rpc instance that exposes the Trezoa JSON RPC API given a cluster URL and some optional transport config. See createDefaultRpcTransport for the shape of the transport config.

createTrezoaRpcFromTransport(transport)

Creates a Rpc instance that exposes the Trezoa JSON RPC API given the supplied RpcTransport.