Skip to content

Commit

Permalink
Update the README for @solana/rpc-api
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Jul 26, 2024
1 parent b7e6465 commit 6ba31f8
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion packages/rpc-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,46 @@

# @solana/rpc-api

TODO
This package contains types that describe the [methods](https://solana.com/docs/rpc/http) of the Solana JSON RPC API, and utilities for creating a `RpcApi` implementation with sensible defaults. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@experimental`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).

Each RPC method is described in terms of a TypeScript interface of the following form:

```ts
interface ExampleApi extends RpcApiMethods {
getSomething(address: Address): Something;
}
```

A `RpcApi` that implements `ExampleApi` will ultimately expose its defined methods on any `Rpc` that uses it.

```ts
const rpc: Rpc<ExampleApi> = createExampleRpc(/* ... */);
const something: Something = await rpc.getSomething(address('95DpK3y3GF7U8s1k4EvZ7xqyeCkhsHeZaE97iZpHUGMN')).send();
```

## Types

### `SolanaRpcApi{Devnet|Testnet|Mainnet}`

These types represent the RPC methods available on a specific Solana cluster.

For instance, the test clusters support the `RequestAirdropApi` while mainnet does not.

## Functions

### `createSolanaRpcApi(config)`

Creates a `RpcApi` implementation of the Solana JSON RPC API with some default behaviours.

The default behaviours include:

- A transform that converts `bigint` inputs to `number` for compatiblity with version 1.0 of the Solana JSON RPC.
- A transform that calls the config's `onIntegerOverflow` handler whenever a `bigint` input would overflow a JavaScript IEEE 754 number. See [this](https://github.com/solana-labs/solana-web3.js/issues/1116) GitHub issue for more information.
- A transform that applies a default commitment wherever not specified

#### Arguments

A config object with the following properties:

- `defaultCommitment`: An optional default `Commitment` value. Given an RPC method that takes `commitment` as a parameter, this value will be used when the caller does not supply one.
- `onIntegerOverflow(methodName, keyPath, value): void`: An optional function that will be called whenever a `bigint` input exceeds that which can be expressed using JavaScript numbers. This is used in the default `SolanaRpcApi` to throw an exception rather than to allow truncated values to propagate through a program.

0 comments on commit 6ba31f8

Please sign in to comment.