{"_id":"@axvn-vn/kit-plugin-rpc","_rev":"3-3ab926d391e3249e5e1b61d3c37e7c63","name":"@axvn-vn/kit-plugin-rpc","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"@axvn-vn/kit-plugin-rpc","version":"0.0.0","keywords":["kit","plugin","rpc","solana"],"license":"MIT","_id":"@axvn-vn/kit-plugin-rpc@0.0.0","maintainers":[{"name":"davidtran76","email":"Farm15ceo@gmail.com"}],"homepage":"https://github.com/anza-xyz/kit-plugins#readme","bugs":{"url":"http://github.com/anza-xyz/kit-plugins/issues"},"dist":{"shasum":"68cb0de85c15243207ce17dda5e26e2aa7db0382","tarball":"https://registry.npmjs.org/@axvn-vn/kit-plugin-rpc/-/kit-plugin-rpc-0.0.0.tgz","fileCount":34,"integrity":"sha512-P3BUkmK4gNyNgj3IoTiy0aw04SpwMgLLWjn0OEnUv7r+jEQtioeppmcTYjpLNVH0VhirhQlcJ/+SjmtKI93HDA==","signatures":[{"sig":"MEYCIQCx8gc9MiEYWcE/8y3zoGqBP5fqoQckSm6pGkBTrPezSQIhANoN6SZmzW7F3knNvaPtGk8OhpItj40TWf+dCUSsyghJ","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":640073},"main":"./dist/index.node.cjs","type":"commonjs","types":"./dist/types/index.d.ts","module":"./dist/index.node.mjs","browser":{"./dist/index.node.cjs":"./dist/index.browser.cjs","./dist/index.node.mjs":"./dist/index.browser.mjs"},"exports":{"node":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"types":"./dist/types/index.d.ts","browser":{"import":"./dist/index.browser.mjs","require":"./dist/index.browser.cjs"},"react-native":"./dist/index.react-native.mjs"},"scripts":{"dev":"vitest --project node","test":"pnpm test:types && pnpm test:treeshakability && pnpm test:unit","test:unit":"vitest run","test:types":"tsc --noEmit","test:treeshakability":"for file in dist/index.*.mjs; do agadoo $file; done"},"_npmUser":{"name":"davidtran76","email":"Farm15ceo@gmail.com"},"repository":{"url":"git+https://github.com/anza-xyz/kit-plugins.git","type":"git"},"_npmVersion":"11.17.0","description":"RPC support for Kit clients","directories":{},"sideEffects":false,"_nodeVersion":"24.19.0","browserslist":["supports bigint and not dead","maintained node versions"],"dependencies":{"@axvn-vn/kit-plugin-instruction-plan":"0.18.0"},"react-native":"./dist/index.react-native.mjs","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"peerDependencies":{"@axvn-vn/kit":"^8.0.0"},"_npmOperationalInternal":{"tmp":"tmp/kit-plugin-rpc_0.0.0_1787355409085_0.11963120953864426","host":"s3://npm-registry-packages-npm-production"},"deprecated":"DEPRECATED: This package has been removed. Do not use."}},"time":{"created":"2026-08-21T23:36:48.759Z","modified":"2026-08-22T16:11:23.229Z","0.0.0":"2026-08-21T23:36:49.236Z"},"bugs":{"url":"http://github.com/anza-xyz/kit-plugins/issues"},"license":"MIT","homepage":"https://github.com/anza-xyz/kit-plugins#readme","keywords":["kit","plugin","rpc","solana"],"repository":{"url":"git+https://github.com/anza-xyz/kit-plugins.git","type":"git"},"description":"RPC support for Kit clients","maintainers":[{"name":"davidtran76","email":"Farm15ceo@gmail.com"},{"name":"nhamhuan","email":"Nhamhuan@gmail.com"}],"readme":"# Kit Plugins ➤ RPC\n\n[![npm][npm-image]][npm-url]\n[![npm-downloads][npm-downloads-image]][npm-url]\n\n[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/kit-plugin-rpc.svg?style=flat\n[npm-image]: https://img.shields.io/npm/v/@solana/kit-plugin-rpc.svg?style=flat&label=%40solana%2Fkit-plugin-rpc\n[npm-url]: https://www.npmjs.com/package/@solana/kit-plugin-rpc\n\nThis package provides plugins that add RPC functionality to your Kit clients.\n\n## Installation\n\n```sh\npnpm install @solana/kit-plugin-rpc\n```\n\n## `solanaRpc` plugin\n\nThe `solanaRpc` plugin sets up a full Solana RPC client in a single call. It installs an RPC connection, RPC Subscriptions, minimum balance computation, transaction planning, and transaction execution on the client.\n\nThe client must have a `payer` set before applying this plugin.\n\n### Installation\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaRpc } from '@solana/kit-plugin-rpc';\nimport { payer } from '@solana/kit-plugin-signer';\n\nconst client = createClient()\n    .use(payer(myPayer))\n    .use(solanaRpc({ rpcUrl: 'https://api.mainnet-beta.solana.com' }));\n```\n\n### Options\n\nAll options are provided via a `SolanaRpcConfig` object:\n\n- `rpcUrl` **(required)**: URL of the Solana RPC endpoint.\n- `rpcSubscriptionsUrl`: URL of the RPC Subscriptions endpoint. Defaults to the `rpcUrl` with the protocol changed from `http` to `ws`. As a convenience, the exact strings `http://127.0.0.1:8899` and `http://localhost:8899` (the canonical local validator RPC endpoints) are rewritten to port `8900`. The match is exact-string only — any other host, scheme, or port (including `https://localhost:8899` or `http://0.0.0.0:8899`) is left untouched. Pass `rpcSubscriptionsUrl` explicitly when your RPC and WebSocket endpoints use different ports.\n- `rpcConfig`: Optional configuration forwarded to `createSolanaRpc`.\n- `rpcSubscriptionsConfig`: Optional configuration forwarded to `createSolanaRpcSubscriptions`.\n- `transactionConfig`: Options to configure how transaction messages are created. See the `rpcTransactionPlanner` options below.\n- `maxConcurrency`: Maximum number of concurrent transaction executions. Defaults to 10.\n- `skipPreflight`: Whether to always skip preflight simulation. Defaults to `false`.\n\n### Features\n\n- `rpc`: Call any Solana RPC method.\n- `rpcSubscriptions`: Subscribe to Solana RPC notifications.\n- `getMinimumBalance`: Compute minimum lamports for rent exemption.\n- `planTransaction(s)`: Plan instructions into transaction messages without executing them.\n- `sendTransaction(s)`: Plan and execute instructions, instruction plans, or transaction messages in one call.\n- `transactionPlanner` / `transactionPlanExecutor` (deprecated): Fields kept for backward compatibility. Use `planTransaction(s)` / `sendTransaction(s)` instead.\n\n## `solanaMainnetRpc` plugin\n\nA convenience wrapper around `solanaRpc` that types the connection as a mainnet URL, preventing accidental use of devnet-only features such as airdrops.\n\n### Installation\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaMainnetRpc } from '@solana/kit-plugin-rpc';\nimport { payer } from '@solana/kit-plugin-signer';\n\nconst client = createClient()\n    .use(payer(myPayer))\n    .use(solanaMainnetRpc({ rpcUrl: 'https://api.mainnet-beta.solana.com' }));\n```\n\n### Features\n\n_See `solanaRpc` for available features._\n\n## `solanaDevnetRpc` plugin\n\nA convenience wrapper around `solanaRpc` that defaults to the public devnet endpoint (`https://api.devnet.solana.com`) and includes airdrop support for requesting SOL from the faucet.\n\n### Installation\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaDevnetRpc } from '@solana/kit-plugin-rpc';\nimport { payerFromFile } from '@solana/kit-plugin-signer';\n\nconst client = createClient().use(payerFromFile('~/.config/solana/id.json')).use(solanaDevnetRpc());\n```\n\n### Features\n\n_See `solanaRpc` for available features, plus:_\n\n- `airdrop`: Request SOL from the devnet faucet.\n    ```ts\n    await client.airdrop(address('HQVxiMVDoV9jzG4tpoxmDZsNfWvaHXm8DGGv93Gka75v'), lamports(1_000_000_000n));\n    ```\n\n## `solanaTestnetRpc` plugin\n\nA convenience wrapper around `solanaRpc` that defaults to the public testnet endpoint (`https://api.testnet.solana.com`) and includes airdrop support for requesting SOL from the faucet.\n\n### Installation\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaTestnetRpc } from '@solana/kit-plugin-rpc';\nimport { payerFromFile } from '@solana/kit-plugin-signer';\n\nconst client = createClient().use(payerFromFile('~/.config/solana/id.json')).use(solanaTestnetRpc());\n```\n\n### Features\n\n_See `solanaRpc` for available features, plus:_\n\n- `airdrop`: Request SOL from the testnet faucet.\n    ```ts\n    await client.airdrop(address('HQVxiMVDoV9jzG4tpoxmDZsNfWvaHXm8DGGv93Gka75v'), lamports(1_000_000_000n));\n    ```\n\n## `solanaLocalRpc` plugin\n\nA convenience wrapper around `solanaRpc` that defaults to `http://127.0.0.1:8899` for the RPC and `ws://127.0.0.1:8900` for subscriptions, and includes airdrop support.\n\n### Installation\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaLocalRpc } from '@solana/kit-plugin-rpc';\nimport { payerFromFile } from '@solana/kit-plugin-signer';\n\nconst client = createClient().use(payerFromFile('~/.config/solana/id.json')).use(solanaLocalRpc());\n```\n\n### Features\n\n_See `solanaRpc` for available features, plus:_\n\n- `airdrop`: Request SOL from the local validator faucet.\n    ```ts\n    await client.airdrop(address('HQVxiMVDoV9jzG4tpoxmDZsNfWvaHXm8DGGv93Gka75v'), lamports(1_000_000_000n));\n    ```\n\n## `solanaRpcConnection` plugin\n\nThe `solanaRpcConnection` plugin creates a Solana RPC and Solana RPC Subscriptions from a cluster URL and installs both on the client.\n\n### Installation\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaRpcConnection } from '@solana/kit-plugin-rpc';\n\nconst client = createClient().use(solanaRpcConnection({ rpcUrl: 'https://api.mainnet-beta.solana.com' }));\n```\n\nYou may wrap your RPC URL using the `mainnet`, `devnet`, or `testnet` helpers from `@solana/kit`. When you do, the returned RPC API will be adjusted to match the selected cluster since some RPC features are not available on all clusters.\n\n```ts\nimport { mainnet } from '@solana/kit';\n\nconst client = createClient().use(solanaRpcConnection({ rpcUrl: mainnet('https://api.mainnet-beta.solana.com') }));\n```\n\n### Options\n\nAll options are provided via a `SolanaRpcConnectionConfig` object:\n\n- `rpcUrl` **(required)**: URL of the Solana RPC endpoint.\n- `rpcSubscriptionsUrl`: URL of the RPC Subscriptions endpoint. Defaults to the `rpcUrl` with the protocol changed from `http` to `ws`. As a convenience, the exact strings `http://127.0.0.1:8899` and `http://localhost:8899` (the canonical local validator RPC endpoints) are rewritten to port `8900`. The match is exact-string only — any other host, scheme, or port (including `https://localhost:8899` or `http://0.0.0.0:8899`) is left untouched. Pass `rpcSubscriptionsUrl` explicitly when your RPC and WebSocket endpoints use different ports.\n- `rpcConfig`: Optional configuration forwarded to `createSolanaRpc`.\n- `rpcSubscriptionsConfig`: Optional configuration forwarded to `createSolanaRpcSubscriptions`.\n\n### Features\n\n- `rpc`: Call any Solana RPC method using type-safe methods.\n    ```ts\n    const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send();\n    ```\n- `rpcSubscriptions`: Subscribe to Solana RPC notifications using async iterators.\n    ```ts\n    const slotNotifications = await client.rpcSubscriptions.slotNotifications({ commitment: 'confirmed' }).subscribe();\n    for await (const slotNotification of slotNotifications) {\n        console.log('Got a slot notification', slotNotification);\n    }\n    ```\n\n## `rpcAirdrop` plugin\n\nThis plugin adds an `airdrop` method to your Kit client that requests SOL airdrops via the RPC and RPC Subscriptions transports.\n\n> [!NOTE]\n> Airdrop is only available on test clusters (devnet, testnet) and local validators. Using this plugin with a mainnet RPC will produce a TypeScript error.\n\n### Installation\n\nThe client must have `rpc` and `rpcSubscriptions` installed before applying this plugin.\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaRpcConnection, rpcAirdrop } from '@solana/kit-plugin-rpc';\n\nconst client = createClient()\n    .use(solanaRpcConnection({ rpcUrl: 'http://127.0.0.1:8899' }))\n    .use(rpcAirdrop());\n```\n\n### Features\n\n- `airdrop`: An asynchronous helper function that airdrops a specified amount of lamports to a given address.\n    ```ts\n    await client.airdrop(address('HQVxiMVDoV9jzG4tpoxmDZsNfWvaHXm8DGGv93Gka75v'), lamports(1_000_000_000n));\n    ```\n\n## `rpcGetMinimumBalance` plugin\n\nThis plugin adds a `getMinimumBalance` method to your Kit client that computes the minimum lamports required for an account with a given data size, using the `getMinimumBalanceForRentExemption` RPC method.\n\n### Installation\n\nThe client must have `rpc` installed before applying this plugin.\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { solanaRpcConnection, rpcGetMinimumBalance } from '@solana/kit-plugin-rpc';\n\nconst client = createClient()\n    .use(solanaRpcConnection({ rpcUrl: 'https://api.mainnet-beta.solana.com' }))\n    .use(rpcGetMinimumBalance());\n```\n\n### Features\n\n- `getMinimumBalance`: An asynchronous helper that returns the minimum lamports required for an account with the given data size. By default, the 128-byte account header is included on top of the provided space.\n\n    ```ts\n    // Minimum balance for an account with 100 bytes of data (plus header).\n    const balance = await client.getMinimumBalance(100);\n\n    // Minimum balance for exactly 100 bytes (without adding the header).\n    const rawBalance = await client.getMinimumBalance(100, { withoutHeader: true });\n    ```\n\n## `rpcTransactionPlanner` plugin\n\nAdds `planTransaction` and `planTransactions` to the client, using a planner that plans instructions into transaction messages with a fee payer, provisory resource limits (a compute unit limit, plus a loaded accounts data size limit for version 1 transactions), and optional priority fees. The fee payer is read from `client.payer` lazily, at plan time, so a dynamic payer (such as a connected wallet) is always respected.\n\n### Usage\n\nThe client must have a `payer` set before installing the plugin.\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { rpcTransactionPlanSendingExecutor, rpcTransactionPlanner, solanaRpcConnection } from '@solana/kit-plugin-rpc';\nimport { generatedPayer } from '@solana/kit-plugin-signer';\n\nconst client = await createClient()\n    .use(solanaRpcConnection({ rpcUrl: 'https://api.mainnet-beta.solana.com' }))\n    .use(generatedPayer())\n    .use(rpcTransactionPlanner())\n    .use(rpcTransactionPlanSendingExecutor());\n\nconst transactionPlan = await client.planTransactions(myInstructionPlan);\n```\n\n### Options\n\nAll options are provided via a `TransactionPlannerConfig` object. Its shape is discriminated by the transaction `version`.\n\nFor legacy and version 0 transactions:\n\n- `version`: The transaction message version to use. Accepts `0` or `'legacy'`. Defaults to `0`.\n- `microLamportsPerComputeUnit`: The priority fee in micro-lamports per compute unit, added as a `setComputeUnitPrice` instruction. Defaults to no priority fees.\n- `estimateResourceLimits`: Whether to estimate and set resource limits by simulating before sending. Set to `false` to skip estimation and reserve no provisory limits, which is useful for transactions close to the message size limit. Defaults to `true`.\n\nVersion 1 transactions are defined for forward compatibility but are not yet buildable by `@solana/kit`; passing `version: 1` currently throws. When available, version 1 will accept `priorityFeeLamports` (a flat total in lamports) instead of `microLamportsPerComputeUnit`, alongside the shared `estimateResourceLimits` option.\n\n## `rpcTransactionPlanSendingExecutor` plugin\n\nAdds `sendTransaction` and `sendTransactions` to the client, using an executor that estimates resource limits, signs, and sends transactions via RPC. Resource limit estimation covers the compute unit limit and, for version 1 transactions, the loaded accounts data size limit.\n\n### Usage\n\nThe client must have `rpc` and `rpcSubscriptions` configured, and a transaction planner installed, before installing this plugin — sending plans through the client's planning functions.\n\n```ts\nimport { createClient } from '@solana/kit';\nimport { rpcTransactionPlanSendingExecutor, rpcTransactionPlanner, solanaRpcConnection } from '@solana/kit-plugin-rpc';\nimport { generatedPayer } from '@solana/kit-plugin-signer';\n\nconst client = await createClient()\n    .use(solanaRpcConnection({ rpcUrl: 'https://api.mainnet-beta.solana.com' }))\n    .use(generatedPayer())\n    .use(rpcTransactionPlanner())\n    .use(rpcTransactionPlanSendingExecutor());\n\nconst transactionPlanResult = await client.sendTransactions(myInstructionPlan);\n```\n\n### Options\n\nAll options are provided via a `RpcTransactionPlanExecutorConfig` object:\n\n- `estimateResourceLimits`: Whether to estimate and set resource limits by simulating before sending (default: `true`). This should match the `estimateResourceLimits` option on the planner; `solanaRpc` keeps them in sync automatically.\n- `getComputeUnitLimitFromEstimate`: A `(estimatedComputeUnits: number) => number` function that maps the estimated compute unit consumption to the compute unit limit to set, adding headroom for variation between simulation and execution. Defaults to a function that adds a buffer on top of the estimate of at least 300 compute units, or a margin that decays linearly from 10% at low estimates to 2% at 500,000 compute units and above, whichever is greater. The result is always capped at 1,400,000 (the per-transaction maximum).\n- `maxConcurrency`: Maximum number of concurrent executions (default: 10).\n- `skipPreflight`: Whether to skip the preflight simulation when sending transactions (default: `false`).\n\n### Result context\n\nAs it works through a transaction, the executor records the planned message (once its blockhash lifetime and resource limits are set), the fully signed transaction, and the signature it was sent under. A successful plan result carries all three on its `context`, and the exported `RpcSendContext` type names that shape so you can annotate results yourself.\n\n```ts\nimport { SuccessfulSingleTransactionPlanResult } from '@solana/kit';\nimport { RpcSendContext } from '@solana/kit-plugin-rpc';\n\nfunction logSentTransaction(result: SuccessfulSingleTransactionPlanResult<RpcSendContext>) {\n    console.log(\n        `Sent ${result.context.signature} using blockhash ${result.context.message.lifetimeConstraint.blockhash}`,\n    );\n}\n```\n\nBecause the context is filled in as execution progresses, a transaction that fails or is canceled part way through carries only what was recorded before it stopped. Failed and canceled results therefore type the context as partial — only successful results guarantee every field.\n\nThe `sendTransaction` and `sendTransactions` functions installed by this plugin propagate this context type, so their results carry a typed `RpcSendContext` without any annotation needed.\n\n### Preflight and Resource Limit Estimation\n\nBy default, the executor estimates resource limits by simulating the transaction before sending it. This covers the compute unit limit and, for version 1 transactions, the loaded accounts data size limit. When estimation is performed, preflight is skipped to avoid a redundant second simulation. When every applicable resource limit is already explicitly set (no estimation needed), preflight runs as the only simulation.\n\nSetting `skipPreflight: true` changes the behavior:\n\n- Preflight is always skipped regardless of whether estimation was performed.\n- If the resource limit estimation simulation fails, the consumed resources from the failed simulation are used to set the limits (with the compute unit buffer from `getComputeUnitLimitFromEstimate` applied) so the transaction still reaches the validator. This is useful for debugging failed transactions in an explorer.\n\n| Scenario            | `skipPreflight: false` (default) | `skipPreflight: true`                  |\n| ------------------- | -------------------------------- | -------------------------------------- |\n| Estimation succeeds | Set limits, skip preflight       | Set limits, skip preflight             |\n| Estimation fails    | Throw                            | Use consumed resources, skip preflight |\n| Explicit limits set | Run preflight                    | Skip preflight                         |\n\nSet `estimateResourceLimits: false` to opt out of resource limit estimation entirely. The planner then reserves no provisory resource limits and the executor does not simulate to estimate or inject any; any explicit resource limits already present on the message are preserved. This is useful for transactions close to the message size limit, where adding a compute budget instruction would make an otherwise valid transaction too large.\n\nNote that disabling estimation does not disable preflight. When `estimateResourceLimits: false` and `skipPreflight` is left at its default `false`, the executor still runs a preflight simulation when sending — this becomes the only simulation. To avoid all simulation overhead, set `skipPreflight: true` as well.\n\nWhen using `solanaRpc`, both the planner and executor read `estimateResourceLimits` from a single place: `transactionConfig`.\n\n```ts\nconst client = createClient()\n    .use(payer(myPayer))\n    .use(\n        solanaRpc({\n            rpcUrl: 'https://api.mainnet-beta.solana.com',\n            skipPreflight: true,\n            transactionConfig: { estimateResourceLimits: false },\n        }),\n    );\n```\n\n#### Compute unit buffer\n\nBecause a transaction can consume slightly more compute units at execution time than during simulation, the executor adds a buffer to the estimated compute unit limit. By default this buffer is the greater of a fixed minimum of 300 compute units and a margin that decays linearly from 10% at low estimates to 2% at 500,000 compute units and above, added on top of the estimate.\n\nOverride this by passing a `getComputeUnitLimitFromEstimate` function that maps the raw estimate to the limit to set. It is applied on both successful estimation and the `skipPreflight` recovery path. The resulting limit is always capped at 1,400,000, the maximum number of compute units allowed per transaction, including for custom functions.\n\n```ts\nconst client = createClient()\n    .use(payer(myPayer))\n    .use(\n        solanaRpc({\n            rpcUrl: 'https://api.mainnet-beta.solana.com',\n            // Add a flat 20% buffer instead of the default curve.\n            getComputeUnitLimitFromEstimate: estimatedComputeUnits => Math.ceil(estimatedComputeUnits * 1.2),\n        }),\n    );\n```\n\n## Deprecated plugins\n\nThe following plugins are still exported for backward compatibility but are deprecated. Prefer `solanaRpcConnection` for new code.\n\n- `rpcConnection(rpc)` / `rpcSubscriptionsConnection(rpcSubscriptions)`: Trivial wrappers around `extendClient`. Inline `extendClient({ rpc })` or `extendClient({ rpcSubscriptions })` instead, or use `solanaRpcConnection` when starting from a cluster URL.\n- `solanaRpcSubscriptionsConnection(url, config?)`: No longer needed because `solanaRpcConnection` installs both `rpc` and `rpcSubscriptions`.\n- `rpcTransactionPlanExecutor(config?)`: Only sets the deprecated `client.transactionPlanExecutor` field. Use `rpcTransactionPlanSendingExecutor` instead, which installs `sendTransaction` and `sendTransactions` alongside the executor.\n\n    ```ts\n    // Before\n    const client = await createClient()\n        .use(rpcTransactionPlanner())\n        .use(rpcTransactionPlanExecutor())\n        .use(planAndSendTransactions());\n\n    // After\n    const client = await createClient().use(rpcTransactionPlanner()).use(rpcTransactionPlanSendingExecutor());\n    ```\n","readmeFilename":"README.md"}