Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana/rpc-transport

Package Overview
Dependencies
Maintainers
13
Versions
602
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/rpc-transport

Network transports for accessing the Solana JSON RPC API

  • 2.0.0-experimental.0a86f01
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
483
increased by3.43%
Maintainers
13
Weekly downloads
 
Created
Source

npm npm-downloads semantic-release
code-style-prettier

@solana/rpc-transport

This package implements a JSON-RPC client with which you can interact with the Solana network. It can be used standalone, in combination with an RPC specification such as @solana/rpc-core, but it is also exported as part of the Solana JavaScript SDK @solana/web3.js@experimental.

Configuration

A new transport created with createJsonRpc() can be configured as follows:

api (required)

An object that conforms to IRpcApi<TMethods>, where TMethods is an interface that specifies the type of every RPC function.

interface ExampleApi {
    getBlocks(startSlot: number, endSlot: number): ReadonlyArray<number>;
}
With no concrete implementation

Crucially, this object does not need to provide implementations of those methods. This allows an infinite number of JSON-RPC methods to be added to the API without affecting the size of the client bundle.

Absent a concrete implementation, @solana/rpc-transport will simply send the function name and its arguments to the RPC as the JSON-RPC method and params. For example, if no concrete implementation for getBlocks is provided in api, the following call:

rpc.getBlocks(1, 20).send();

…will result in an RPC call whose method is getBlocks and whose params are [1, 20].

With an optional concrete implementation

If you would like to modify the inputs to a given method call before they are sent, or would like to post-process the response from the JSON-RPC server, you may supply a concrete implementation for one or more methods of api.

const api = {
    getBlocks(startSlot: number, endSlot: number): ReadonlyArray<number> {
        return {
            // Optionally pre-process the method name,
            methodName: 'getBlocksInRange',
            // Pre-process the inputs any way you like.
            params: [assertIsInteger(startSlot), assertIsInteger(endSlot)],
            // Provide an optional function to modify the response.
            responseProcessor: response => ({
                confirmedBlocks: response,
                queryRange: [startSlot, endSlot],
            }),
        };
    },
};

transport (required)

A function that implements a wire transport.

type RpcTransportConfig = Readonly<{
    payload: unknown;
    signal?: AbortSignal;
}>;

export interface IRpcTransport {
    <TResponse>(config: RpcTransportConfig): Promise<TResponse>;
}

An HTTP wire transport is supplied with this package, but you can supply any wire transport that conforms to IRpcTransport.

Keywords

FAQs

Package last updated on 31 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc