# RPC

> Source: https://taquito.io/docs/25.2.0/rpc_package

You can use the RPC client package to query the RPC API of your chosen node. The higher-level [`@taquito/taquito`](https://taquito.io/typedoc/modules/_taquito_rpc.html) package builds on this RPC package.

In general, you won't need to use this package directly, but it is available for use should you want specific data and need to bypass the higher-level abstractions in Taquito.

Methods in the RPC package map one-to-one to the corresponding Tezos RPC API endpoints. All responses from the RPC are returned with TypeScript types. No other parsing or compositions are done at this level.

## Rate limits and retries

When an RPC node responds with HTTP 429, Taquito's default HTTP backend can retry a GET request. The backend honors `Retry-After` as an integer number of seconds or an HTTP date. A valid delay above 30 seconds returns the original HTTP error. If the header is missing or invalid, the backend uses exponential backoff with jitter. In browsers the RPC server must expose `Retry-After` through CORS for the backend to read it.

HTTP 429 retries apply only to GET requests. GET requests and selected POST endpoints, including `run_code`, `run_view` and `pack_data`, can also retry HTTP 502, 503 and 504 or transient transport failures such as a connection reset. If an operation injection retry returns an error, check the operation hash before reporting a failure. The first attempt may have reached the node.

The default budget is one retry shared across rate limits, gateway errors and transport failures. In Node.js, set `TAQUITO_HTTP_RETRY_COUNT` to change the budget or to `0` to disable retries. Set `TAQUITO_HTTP_RETRY_BASE_MS` to change the base backoff delay, which defaults to 100 ms. Set both variables before importing Taquito. Aborting the request also cancels a retry wait.

## Examples

The `RpcClient` constructor takes the URL of the node you want to use and the chain ID.
```js
// Initializing the RPC client

const client = new RpcClient(' https://tezos-shadownet.octez.io/', 'NetXLH1uAxK7CCh');
```

The balance is returned as a `BigNumber` and must be converted to a number to output it. Please note that the returned value is in mutez (micro ꜩ), so if you need the balance in ꜩ, you can divide it by 1000000.
```js
/* Fetching the spendable balance of an account
 * using the client set up above */

const balance = await client.getBalance('tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb');
console.log('Balance:', balance.toNumber());
```

You can use the RPC client to get the head block information.
```js
// gets head block
const block = await client.getBlock();
console.log('Head block:', block);
```

If it's the head block hash you are looking for, you can easily get it with the `getBlockHash` method.
```js
// gets head block hash
const blockHash = await client.getBlockHash();
console.log('Head block hash:', blockHash);
```

This method returns some blockchain constants pertaining for example to the gas limits or the block information.
```js
// gets constants
const constants = await client.getConstants();
console.log('Constants:', constants);
```

This method returns the balance of the contract, the code, and the storage.
```js
// gets contract
const contractExample = 'KT1J4E79F1qL6kGBSQ3yXBdXmuq5j4FNThK2';
const contract = await client.getContract(contractExample);
console.log('Contract:', contract);
```

You can also get a list of the contract entry points as an object whose keys are the entry point names and whose values are the expected parameters in JSON format.
```js
// gets contract entrypoints
const entrypoints = await client.getEntrypoints(contractExample);
console.log('Entrypoints:', entrypoints);
```

The `getScript` method returns the contract's script as a 3 key/value pair object: a key for the parameter, a key for the storage, and a key for the code.
```js
// gets contract script
const script = await client.getScript(contractExample);
console.log('Contract script:', script);
```

You also have access to the storage of the contract using the `getStorage` method.
```js
// gets contract storage
const storage = await client.getStorage(contractExample);
console.log('Contract storage:', storage);
```

You can simulate the `PACK` instruction from Michelson with the `packData` method.
```js
// packs data
const packedData = await client.packData({ data: { string: 'test' }, type: { prim: 'string' } });
console.log('Packed data:', packedData);
```

This function will execute TZIP-4 views normally referred to as 'Lambda Views'. You can learn more about TZIP-4 [here](https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-4/tzip-4.md#view-entrypoints)
```js
// runs view
const view = await client.runView({
  contract: 'contractAddress',
  entrypoint: 'contractEntrypoint',
  chain_id: 'chainId',
  input: {
    string: 'testInput'
  }
});
```

## Full documentation

Typedoc information is available [here](https://taquito.io/typedoc/classes/_taquito_rpc.RpcClient).

## BLS operations

The BLS methods call the node's root `/bls` endpoints. They do not require a chain
or block path, a signer, or an operation. Use an Octez node that exposes these
endpoints.

| Method | POST endpoint | Result |
| --- | --- | --- |
| `aggregatePublicKeys` | `/bls/aggregate_public_keys` | An object with `public_key` and `public_key_hash`, or `null` |
| `aggregateProofs` | `/bls/aggregate_proofs` | A proof signature string, or `null` |
| `checkProof` | `/bls/check_proof` | A boolean |
| `aggregateSignatures` | `/bls/aggregate_signatures` | A signature string, or `null` |
| `thresholdSignatures` | `/bls/threshold_signatures` | A signature string, or `null` |

`checkProof` takes a public key and its proof of possession. `aggregatePublicKeys`
takes an array of those objects. `aggregateProofs` takes an object with `public_key`
(the aggregate `BLpk...` key) and `proofs` (an array of each participant's proof of
possession over that aggregate key, produced via `signer.provePossession(aggregatePk)`).
Keys, proofs, and signatures use Base58Check encoding. The following example uses
fixed public test values:

```js

const client = new RpcClient('https://rpc.shadownet.teztnets.com');
const key = {
  public_key: 'BLpk1wMU34nS7N96D2owyejLxQtwZwLARLg6tdTFMP5N8fz6yCiLogfFXkYo9ZHnZ95Kba3D3cvt',
  proof: 'BLsig9cW2ffM82s8cZWNDQTmecxHPHmJcTUh5DF2dVP7GV7oUmmptd4JpxBvSyE1VDeLtGyV68KaTuaEM1qiSUELMqkdwCLJFDQYGL6ZZLZDEUAfyu3Vu3ivs66jhV8ANwt3tKg6qABoqx',
};

const valid = await client.checkProof(key);
console.log(valid); // true

const aggregate = await client.aggregatePublicKeys([key]);
if (aggregate !== null) {
  console.log(aggregate.public_key_hash); // 'tz4AQcKaQU1sUzsmPTX43qnK4ddkCeeknJnf'
}
```

`aggregateSignatures` takes an object with `public_key`, `message`, and
`signature_shares`. The message is hexadecimal without a `0x` prefix. Its
`signature_shares` value is an array of signature strings.

`thresholdSignatures` takes the same fields, but each signature share is an
object with `id` and `signature`. The node validates share IDs as signed 8-bit
integers, from -128 through 127.

A failed proof check can return `false`, and failed aggregation can return
`null`. HTTP and transport failures still reject the promise. Malformed input can
also cause an HTTP error. Handle these rejections separately from `false` and
`null` results.

`RpcClientCache` forwards these five methods without caching their results.
If you implement `RpcClientInterface` yourself, the original four methods are
required and `aggregateProofs` is optional (`RpcClientCache` throws
`UnsupportedActionError` when the underlying client omits `aggregateProofs`).
Existing RPC methods and cache policies are unchanged.
