diff --git a/content/api-reference/pricing-resources/pricing/compute-unit-costs.mdx b/content/api-reference/pricing-resources/pricing/compute-unit-costs.mdx index 1ca38b210..11e647438 100644 --- a/content/api-reference/pricing-resources/pricing/compute-unit-costs.mdx +++ b/content/api-reference/pricing-resources/pricing/compute-unit-costs.mdx @@ -202,6 +202,14 @@ For more details, check out the [Compute Units](/docs/reference/compute-units#wh * Amount will be pro-rated based on bytes streamed. [Contact us](https://www.alchemy.com/contact-sales) for pre-committed bulk discounts. +# Solana: WebSocket Subscriptions + +[Solana WebSocket subscriptions](/docs/reference/solana-subscription-api-endpoints) (`accountSubscribe`, `programSubscribe`, `logsSubscribe`, etc.) are priced based on **bandwidth:** the amount of data delivered as part of the stream. + +| Bandwidth | CU | +| --------- | ------ | +| 1 byte | .0002 | + # Debug API | Method | CU | Throughput CU | diff --git a/content/api-reference/websockets/solana-subscription-api-endpoints/account-subscribe.mdx b/content/api-reference/websockets/solana-subscription-api-endpoints/account-subscribe.mdx new file mode 100644 index 000000000..68d8415b8 --- /dev/null +++ b/content/api-reference/websockets/solana-subscription-api-endpoints/account-subscribe.mdx @@ -0,0 +1,105 @@ +--- +title: accountSubscribe +description: Subscribe to notifications when one Solana account's lamports or data change. +subtitle: Subscribe to notifications when one Solana account's lamports or data change. +slug: reference/account-subscribe +--- + +The `accountSubscribe` method opens a stream that emits a notification any time the lamports or data of a specified account change. Pair it with [`accountUnsubscribe`](#unsubscribe) to stop receiving notifications. + +# Parameters + +* `pubkey`: `string` - Account pubkey, as a base-58 encoded string. + +* `config` (optional): `object` - Configuration object containing: + + * `commitment`: `string` - The commitment level to use. One of `processed`, `confirmed`, `finalized`. Defaults to `finalized`. + * `encoding`: `string` - Account data encoding. One of `base58`, `base64`, `base64+zstd`, `jsonParsed`. Defaults to `base58`. + +# Request + + + ```shell wscat + // initiate websocket stream first + wscat -c wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY --> + + // then call subscription + {"jsonrpc":"2.0","id":1,"method":"accountSubscribe","params":["CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12",{"encoding":"jsonParsed","commitment":"finalized"}]} + ``` + + ```javascript @solana/web3.js + import { Connection, PublicKey } from '@solana/web3.js' + + const connection = new Connection( + 'https://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + { + wsEndpoint: 'wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + commitment: 'finalized' + } + ) + + const accountPubkey = new PublicKey('CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12') + + const subscriptionId = connection.onAccountChange( + accountPubkey, + (accountInfo, context) => { + console.log('Account update at slot', context.slot, { + lamports: accountInfo.lamports, + owner: accountInfo.owner.toBase58(), + dataLen: accountInfo.data.length + }) + }, + 'finalized' + ) + + // To unsubscribe later: + // await connection.removeAccountChangeListener(subscriptionId) + ``` + + +# Result + + + ```json result + // subscribe response + {"jsonrpc":"2.0","result":23784,"id":1} + + // notification + { + "jsonrpc": "2.0", + "method": "accountNotification", + "params": { + "result": { + "context": { "slot": 5199307 }, + "value": { + "data": ["11116bv5nS2h3y12kD1yUKeMZvGcKLSjQgX6BeV7u1FrjeJcKfsHRTPuR3oZ1EioKtYGiYxpxMG5vpbZLsbcBYBEmZZcMKaSoGx9JZeAuWf", "base58"], + "executable": false, + "lamports": 33594, + "owner": "11111111111111111111111111111111", + "rentEpoch": 635, + "space": 80 + } + }, + "subscription": 23784 + } + } + ``` + + +# Unsubscribe + +Use `accountUnsubscribe` with the subscription id returned by `accountSubscribe` to cancel the stream. + +* `subscription_id`: `number` - The subscription id to cancel. + + + ```shell wscat + {"jsonrpc":"2.0","id":1,"method":"accountUnsubscribe","params":[subscription_id]} + ``` + + +```json result +{"jsonrpc":"2.0","result":true,"id":1} +``` + +When using `@solana/web3.js`, call `connection.removeAccountChangeListener(subscriptionId)` instead of sending the raw JSON-RPC request. diff --git a/content/api-reference/websockets/solana-subscription-api-endpoints/logs-subscribe.mdx b/content/api-reference/websockets/solana-subscription-api-endpoints/logs-subscribe.mdx new file mode 100644 index 000000000..d9ce3a6d3 --- /dev/null +++ b/content/api-reference/websockets/solana-subscription-api-endpoints/logs-subscribe.mdx @@ -0,0 +1,106 @@ +--- +title: logsSubscribe +description: Subscribe to Solana transaction log messages that match a log filter. +subtitle: Subscribe to Solana transaction log messages that match a log filter. +slug: reference/logs-subscribe +--- + +The `logsSubscribe` method opens a stream that emits a notification any time a transaction is committed and its logs match the supplied filter. Pair it with [`logsUnsubscribe`](#unsubscribe) to stop receiving notifications. + +# Parameters + +* `filter`: filter criteria for log subscriptions. Accepts one of: + + * `"all"` - subscribe to all transactions except simple vote transactions. + * `"allWithVotes"` - subscribe to all transactions including simple vote transactions. + * An object: `{ "mentions": [""] }` - subscribe to transactions that mention exactly one of the provided base-58 encoded pubkeys. + +* `config` (optional): `object` - Configuration object containing: + + * `commitment`: `string` - The commitment level. One of `processed`, `confirmed`, `finalized`. Defaults to `finalized`. + +# Request + + + ```shell wscat + // initiate websocket stream first + wscat -c wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY --> + + // then call subscription + {"jsonrpc":"2.0","id":1,"method":"logsSubscribe","params":[{"mentions":["11111111111111111111111111111111"]},{"commitment":"finalized"}]} + ``` + + ```javascript @solana/web3.js + import { Connection, PublicKey } from '@solana/web3.js' + + const connection = new Connection( + 'https://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + { + wsEndpoint: 'wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + commitment: 'finalized' + } + ) + + const subscriptionId = connection.onLogs( + new PublicKey('11111111111111111111111111111111'), + (logs, context) => { + console.log('Logs at slot', context.slot, { + signature: logs.signature, + err: logs.err, + logs: logs.logs + }) + }, + 'finalized' + ) + + // To unsubscribe later: + // await connection.removeOnLogsListener(subscriptionId) + ``` + + +# Result + + + ```json result + // subscribe response + {"jsonrpc":"2.0","result":24040,"id":1} + + // notification + { + "jsonrpc": "2.0", + "method": "logsNotification", + "params": { + "result": { + "context": { "slot": 5208469 }, + "value": { + "signature": "5h6xBEauJ3PK6SWCZ1PGjBvj8vDdWG3KpwATGy1ARAXFSDwt8GFXM7W5Ncn16wmqokgpiKRLuS83KUxyZyv2sUYv", + "err": null, + "logs": [ + "Program 11111111111111111111111111111111 invoke [1]", + "Program 11111111111111111111111111111111 success" + ] + } + }, + "subscription": 24040 + } + } + ``` + + +# Unsubscribe + +Use `logsUnsubscribe` with the subscription id returned by `logsSubscribe` to cancel the stream. + +* `subscription_id`: `number` - The subscription id to cancel. + + + ```shell wscat + {"jsonrpc":"2.0","id":1,"method":"logsUnsubscribe","params":[subscription_id]} + ``` + + +```json result +{"jsonrpc":"2.0","result":true,"id":1} +``` + +When using `@solana/web3.js`, call `connection.removeOnLogsListener(subscriptionId)` instead of sending the raw JSON-RPC request. diff --git a/content/api-reference/websockets/solana-subscription-api-endpoints/program-subscribe.mdx b/content/api-reference/websockets/solana-subscription-api-endpoints/program-subscribe.mdx new file mode 100644 index 000000000..bc6fba905 --- /dev/null +++ b/content/api-reference/websockets/solana-subscription-api-endpoints/program-subscribe.mdx @@ -0,0 +1,114 @@ +--- +title: programSubscribe +description: Subscribe to notifications for accounts owned by a Solana program. +subtitle: Subscribe to notifications for accounts owned by a Solana program. +slug: reference/program-subscribe +--- + +The `programSubscribe` method opens a stream that emits a notification when the lamports or data of any account owned by a given program change. Pair it with [`programUnsubscribe`](#unsubscribe) to stop receiving notifications. + +# Parameters + +* `pubkey`: `string` - Program pubkey, as a base-58 encoded string. + +* `config` (optional): `object` - Configuration object containing: + + * `commitment`: `string` - The commitment level. One of `processed`, `confirmed`, `finalized`. Defaults to `finalized`. + * `encoding`: `string` - Account data encoding. One of `base58`, `base64`, `base64+zstd`, `jsonParsed`. Defaults to `base58`. + * `filters`: `array` (optional) - An array of filter objects (`memcmp` and/or `dataSize`) to narrow which program-owned accounts trigger notifications. + + + `programSubscribe` without filters can produce extremely high volumes of notifications. Use `dataSize` and `memcmp` filters to scope the stream to the accounts you care about. + + +# Request + + + ```shell wscat + // initiate websocket stream first + wscat -c wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY --> + + // then call subscription + {"jsonrpc":"2.0","id":1,"method":"programSubscribe","params":["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",{"encoding":"jsonParsed","filters":[{"dataSize":165}]}]} + ``` + + ```javascript @solana/web3.js + import { Connection, PublicKey } from '@solana/web3.js' + + const connection = new Connection( + 'https://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + { + wsEndpoint: 'wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + commitment: 'finalized' + } + ) + + const programId = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA') + + const subscriptionId = connection.onProgramAccountChange( + programId, + ({ accountId, accountInfo }, context) => { + console.log('Program account update at slot', context.slot, { + account: accountId.toBase58(), + lamports: accountInfo.lamports, + owner: accountInfo.owner.toBase58() + }) + }, + 'finalized', + [{ dataSize: 165 }] + ) + + // To unsubscribe later: + // await connection.removeProgramAccountChangeListener(subscriptionId) + ``` + + +# Result + + + ```json result + // subscribe response + {"jsonrpc":"2.0","result":24040,"id":1} + + // notification + { + "jsonrpc": "2.0", + "method": "programNotification", + "params": { + "result": { + "context": { "slot": 5208469 }, + "value": { + "pubkey": "H4vnBqifaSACnKa7acsxstsY1iV1bvJNxsCY7enrd1hq", + "account": { + "data": ["11116bv5nS2h3y12kD1yUKeMZvGcKLSjQgX6BeV7u1FrjeJcKfsHRTPuR3oZ1EioKtYGiYxpxMG5vpbZLsbcBYBEmZZcMKaSoGx9JZeAuWf", "base58"], + "executable": false, + "lamports": 33594, + "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "rentEpoch": 636, + "space": 80 + } + } + }, + "subscription": 24040 + } + } + ``` + + +# Unsubscribe + +Use `programUnsubscribe` with the subscription id returned by `programSubscribe` to cancel the stream. + +* `subscription_id`: `number` - The subscription id to cancel. + + + ```shell wscat + {"jsonrpc":"2.0","id":1,"method":"programUnsubscribe","params":[subscription_id]} + ``` + + +```json result +{"jsonrpc":"2.0","result":true,"id":1} +``` + +When using `@solana/web3.js`, call `connection.removeProgramAccountChangeListener(subscriptionId)` instead of sending the raw JSON-RPC request. diff --git a/content/api-reference/websockets/solana-subscription-api-endpoints/root-subscribe.mdx b/content/api-reference/websockets/solana-subscription-api-endpoints/root-subscribe.mdx new file mode 100644 index 000000000..c315476de --- /dev/null +++ b/content/api-reference/websockets/solana-subscription-api-endpoints/root-subscribe.mdx @@ -0,0 +1,79 @@ +--- +title: rootSubscribe +description: Subscribe to notifications when the Solana validator sets a new root slot. +subtitle: Subscribe to notifications when the Solana validator sets a new root slot. +slug: reference/root-subscribe +--- + +The `rootSubscribe` method opens a stream that emits a notification each time the validator sets a new root slot. The notification payload is a single number: the slot of the new root. Pair it with [`rootUnsubscribe`](#unsubscribe) to stop receiving notifications. + +# Parameters + +* None + +# Request + + + ```shell wscat + // initiate websocket stream first + wscat -c wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY --> + + // then call subscription + {"jsonrpc":"2.0","id":1,"method":"rootSubscribe"} + ``` + + ```javascript @solana/web3.js + import { Connection } from '@solana/web3.js' + + const connection = new Connection( + 'https://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + { + wsEndpoint: 'wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->' + } + ) + + const subscriptionId = connection.onRootChange((rootSlot) => { + console.log('New root slot:', rootSlot) + }) + + // To unsubscribe later: + // await connection.removeRootChangeListener(subscriptionId) + ``` + + +# Result + + + ```json result + // subscribe response + {"jsonrpc":"2.0","result":0,"id":1} + + // notification + { + "jsonrpc": "2.0", + "method": "rootNotification", + "params": { + "result": 42, + "subscription": 0 + } + } + ``` + + +# Unsubscribe + +Use `rootUnsubscribe` with the subscription id returned by `rootSubscribe` to cancel the stream. + +* `subscription_id`: `number` - The subscription id to cancel. + + + ```shell wscat + {"jsonrpc":"2.0","id":1,"method":"rootUnsubscribe","params":[subscription_id]} + ``` + + +```json result +{"jsonrpc":"2.0","result":true,"id":1} +``` + +When using `@solana/web3.js`, call `connection.removeRootChangeListener(subscriptionId)` instead of sending the raw JSON-RPC request. diff --git a/content/api-reference/websockets/solana-subscription-api-endpoints/signature-subscribe.mdx b/content/api-reference/websockets/solana-subscription-api-endpoints/signature-subscribe.mdx new file mode 100644 index 000000000..9b89597d9 --- /dev/null +++ b/content/api-reference/websockets/solana-subscription-api-endpoints/signature-subscribe.mdx @@ -0,0 +1,95 @@ +--- +title: signatureSubscribe +description: Subscribe to status notifications for one Solana transaction signature. +subtitle: Subscribe to status notifications for one Solana transaction signature. +slug: reference/signature-subscribe +--- + +The `signatureSubscribe` method opens a stream that emits a single notification when a given transaction signature reaches the requested commitment level (or when transaction status changes if `enableReceivedNotification` is set). After the notification fires, the subscription is automatically cancelled. Pair it with [`signatureUnsubscribe`](#unsubscribe) to cancel a subscription before it fires. + +# Parameters + +* `signature`: `string` - Transaction signature, as a base-58 encoded string. + +* `config` (optional): `object` - Configuration object containing: + + * `commitment`: `string` - The commitment level. One of `processed`, `confirmed`, `finalized`. Defaults to `finalized`. + * `enableReceivedNotification`: `boolean` (optional) - When `true`, the subscription also fires a notification when the transaction has been `received` by the node, before reaching the requested commitment. + +# Request + + + ```shell wscat + // initiate websocket stream first + wscat -c wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY --> + + // then call subscription + {"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["2EBVM6cB8vAAD93Ktr6Vd8p67XPbQzCJX47MpReuiCXJAtcjaxpvWpcg9Ege1Nr5Tk3a2GFrByT7WPBjdsTycY9b",{"commitment":"finalized","enableReceivedNotification":false}]} + ``` + + ```javascript @solana/web3.js + import { Connection } from '@solana/web3.js' + + const connection = new Connection( + 'https://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + { + wsEndpoint: 'wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + commitment: 'finalized' + } + ) + + const signature = '2EBVM6cB8vAAD93Ktr6Vd8p67XPbQzCJX47MpReuiCXJAtcjaxpvWpcg9Ege1Nr5Tk3a2GFrByT7WPBjdsTycY9b' + + const subscriptionId = connection.onSignature( + signature, + (result, context) => { + console.log('Signature status at slot', context.slot, result) + }, + 'finalized' + ) + + // The subscription is auto-removed by the node once it fires. + // To remove it manually before it fires: + // await connection.removeSignatureListener(subscriptionId) + ``` + + +# Result + + + ```json result + // subscribe response + {"jsonrpc":"2.0","result":24006,"id":1} + + // notification (commitment reached) + { + "jsonrpc": "2.0", + "method": "signatureNotification", + "params": { + "result": { + "context": { "slot": 5207624 }, + "value": { "err": null } + }, + "subscription": 24006 + } + } + ``` + + +# Unsubscribe + +Use `signatureUnsubscribe` with the subscription id returned by `signatureSubscribe` to cancel a pending subscription. (After the notification has already fired, the subscription is removed automatically.) + +* `subscription_id`: `number` - The subscription id to cancel. + + + ```shell wscat + {"jsonrpc":"2.0","id":1,"method":"signatureUnsubscribe","params":[subscription_id]} + ``` + + +```json result +{"jsonrpc":"2.0","result":true,"id":1} +``` + +When using `@solana/web3.js`, call `connection.removeSignatureListener(subscriptionId)` instead of sending the raw JSON-RPC request. diff --git a/content/api-reference/websockets/solana-subscription-api-endpoints/slot-subscribe.mdx b/content/api-reference/websockets/solana-subscription-api-endpoints/slot-subscribe.mdx new file mode 100644 index 000000000..f10264621 --- /dev/null +++ b/content/api-reference/websockets/solana-subscription-api-endpoints/slot-subscribe.mdx @@ -0,0 +1,87 @@ +--- +title: slotSubscribe +description: Subscribe to notifications when the Solana validator processes a new slot. +subtitle: Subscribe to notifications when the Solana validator processes a new slot. +slug: reference/slot-subscribe +--- + +The `slotSubscribe` method opens a stream that emits a notification each time the validator processes a new slot. Pair it with [`slotUnsubscribe`](#unsubscribe) to stop receiving notifications. + +# Parameters + +* None + +# Request + + + ```shell wscat + // initiate websocket stream first + wscat -c wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY --> + + // then call subscription + {"jsonrpc":"2.0","id":1,"method":"slotSubscribe"} + ``` + + ```javascript @solana/web3.js + import { Connection } from '@solana/web3.js' + + const connection = new Connection( + 'https://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->', + { + wsEndpoint: 'wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->' + } + ) + + const subscriptionId = connection.onSlotChange((slotInfo) => { + console.log('Slot update:', { + slot: slotInfo.slot, + parent: slotInfo.parent, + root: slotInfo.root + }) + }) + + // To unsubscribe later: + // await connection.removeSlotChangeListener(subscriptionId) + ``` + + +# Result + + + ```json result + // subscribe response + {"jsonrpc":"2.0","result":0,"id":1} + + // notification + { + "jsonrpc": "2.0", + "method": "slotNotification", + "params": { + "result": { + "parent": 75, + "root": 42, + "slot": 76 + }, + "subscription": 0 + } + } + ``` + + +# Unsubscribe + +Use `slotUnsubscribe` with the subscription id returned by `slotSubscribe` to cancel the stream. + +* `subscription_id`: `number` - The subscription id to cancel. + + + ```shell wscat + {"jsonrpc":"2.0","id":1,"method":"slotUnsubscribe","params":[subscription_id]} + ``` + + +```json result +{"jsonrpc":"2.0","result":true,"id":1} +``` + +When using `@solana/web3.js`, call `connection.removeSlotChangeListener(subscriptionId)` instead of sending the raw JSON-RPC request. diff --git a/content/api-reference/websockets/solana-subscription-api-endpoints/solana-subscription-api-endpoints.mdx b/content/api-reference/websockets/solana-subscription-api-endpoints/solana-subscription-api-endpoints.mdx new file mode 100644 index 000000000..276e3b528 --- /dev/null +++ b/content/api-reference/websockets/solana-subscription-api-endpoints/solana-subscription-api-endpoints.mdx @@ -0,0 +1,87 @@ +--- +title: Solana Subscription API Endpoints +description: List of Solana PubSub WebSocket subscription methods, grouped by category. +subtitle: List of Solana PubSub WebSocket subscription methods, grouped by category. +slug: reference/solana-subscription-api-endpoints +--- + +# Overview + +Solana exposes a PubSub WebSocket API alongside its standard HTTP JSON-RPC. Each subscription opens a long-lived stream that pushes notifications when on-chain state changes (account data, program-owned accounts, transaction logs, signature status, slots, blocks, votes, and roots). + +Connect to the PubSub endpoint using your Alchemy WebSocket URL: + +```text +wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY --> +``` + + + Solana uses native `*Subscribe` / `*Unsubscribe` methods instead of `eth_subscribe`. Each `*Subscribe` call returns a numeric subscription id which you pass to the matching `*Unsubscribe` to cancel the stream. + + +# Request Format + +Solana PubSub uses [JSON-RPC 2.0](https://www.jsonrpc.org/specification) over a persistent WebSocket connection. + +| Field | Type | Description | +| --------- | -------------------------- | ------------------------------------------------------------------------------------ | +| `jsonrpc` | `string` | JSON-RPC version. Set this to `"2.0"`. | +| `id` | `string \| number \| null` | Client-supplied request identifier. The server echoes it in the subscribe response. | +| `method` | `string` | PubSub method name, such as `accountSubscribe` or `slotSubscribe`. | +| `params` | `array` | Ordered method parameters. Use an empty array when the method takes no parameters. | + +Many subscription methods accept an optional `commitment` parameter. Subscriptions that accept commitment default to `finalized` when unspecified. + +# Notification Format + +After a subscribe request succeeds, the server returns a numeric subscription id in the JSON-RPC response. Later notifications are pushed as JSON-RPC messages with a method-specific notification name and the active subscription id. + +| Field | Type | Description | +| --------------------- | -------- | ------------------------------------------------------------------------------------------------------------ | +| `jsonrpc` | `string` | JSON-RPC version. | +| `method` | `string` | Notification name, such as `accountNotification` or `slotNotification`. | +| `params.result` | `any` | Method-specific notification payload. Many methods include a `context` object and a method-specific `value`. | +| `params.subscription` | `number` | Subscription id returned by the corresponding `*Subscribe` method. | + +# Method Reference + +## Accounts + +| Method | Description | +| ----------------------------------------------------- | ---------------------------------------------------------------------- | +| [`accountSubscribe`](/docs/reference/account-subscribe) | Subscribe to notifications when one account's lamports or data change. | +| [`programSubscribe`](/docs/reference/program-subscribe) | Subscribe to notifications for accounts owned by a program. | + +## Transactions + +| Method | Description | +| --------------------------------------------------------- | ---------------------------------------------------------------- | +| [`logsSubscribe`](/docs/reference/logs-subscribe) | Subscribe to transaction log messages that match a log filter. | +| [`signatureSubscribe`](/docs/reference/signature-subscribe) | Subscribe to status notifications for one transaction signature. | + +## Cluster + +| Method | Description | +| ----------------------------------------------------------------------- | -------------------------------------------------------------------- | +| [`rootSubscribe`](/docs/reference/root-subscribe) | Subscribe to notifications when the validator sets a new root slot. | +| [`slotSubscribe`](/docs/reference/slot-subscribe) | Subscribe to notifications when the validator processes a new slot. | + +# Pricing + +Solana WebSocket subscriptions on Alchemy are billed by **bandwidth** — pro-rated to the exact byte. See [Compute Unit Costs](/docs/reference/compute-unit-costs#solana-websocket-subscriptions) for the per-byte CU rate and PAYG pricing. + + + Broad streams can produce very high bandwidth, especially `programSubscribe` without filters. To keep usage predictable: + + * Prefer the most specific stream and scope with `mentions` / `mentionsAccountOrProgram` / `dataSize` / `memcmp` filters. + * Keep payloads small (e.g. `encoding: "base64"`, `transactionDetails: "signatures"`). + * Set [usage limits](/docs/how-to-set-usage-limits-and-alerts-for-your-account) and [usage alerts](/docs/dashboard-alerts) before running high-volume streams in production. + + +# Supported Networks + + + Check the [Chains](https://dashboard.alchemy.com/chains) page for details about product and chain support! + + ![](https://alchemyapi-res.cloudinary.com/image/upload/v1764179964/docs/api-reference/alchemy-transact/transaction-simulation/523fb8a9a9d899921ee1046d0ff1b389967a9976d1c6112ebbbe071ddd1ef374-image.png) + diff --git a/content/api-reference/websockets/subscription-api.mdx b/content/api-reference/websockets/subscription-api.mdx index c1faa0cfd..f2424c9c1 100644 --- a/content/api-reference/websockets/subscription-api.mdx +++ b/content/api-reference/websockets/subscription-api.mdx @@ -1,7 +1,7 @@ --- title: Subscription API Overview -description: Learn how to subscribe to pending transactions, log events, new blocks and more using WebSockets on Ethereum, Polygon, Arbitrum, and Optimism. -subtitle: Learn how to subscribe to pending transactions, log events, new blocks and more using WebSockets on Ethereum, Polygon, Arbitrum, and Optimism. +description: Learn how to subscribe to pending transactions, log events, new blocks, account and program updates, and more using WebSockets on Ethereum, Polygon, Arbitrum, Optimism, and Solana. +subtitle: Learn how to subscribe to pending transactions, log events, new blocks, account and program updates, and more using WebSockets on Ethereum, Polygon, Arbitrum, Optimism, and Solana. slug: reference/subscription-api --- @@ -28,6 +28,35 @@ For a full list of Subscription API endpoints and supported chains see the [Subs | [monadNewHeads](/docs/reference/monadnewheads) | Fires a notification each time as soon as a block is Proposed and the node has a chance to speculatively execute. | | [monadLogs](/docs/reference/monadlogs) | Emits logs attached to a new block that match certain topic filters as soon as the block is Proposed and the node has a chance to speculatively execute. | +## Solana subscription endpoints + +Solana uses native `*Subscribe` / `*Unsubscribe` PubSub methods (not `eth_subscribe`). Each `*Subscribe` call returns a numeric subscription id that you pass to the matching `*Unsubscribe` to cancel the stream. See the [Solana Subscription API Endpoints](/docs/reference/solana-subscription-api-endpoints) index for shared request/notification format details. + + + **Pricing:** See the [Solana Subscription API Endpoints](/docs/reference/solana-subscription-api-endpoints#pricing) page for a full breakdown. + + +**Accounts** + +| Subscription Type | Description | +| --------------------------------------------------------- | ---------------------------------------------------------------------- | +| [accountSubscribe](/docs/reference/account-subscribe) | Subscribe to notifications when one account's lamports or data change. | +| [programSubscribe](/docs/reference/program-subscribe) | Subscribe to notifications for accounts owned by a program. | + +**Transactions** + +| Subscription Type | Description | +| ------------------------------------------------------------- | ---------------------------------------------------------------- | +| [logsSubscribe](/docs/reference/logs-subscribe) | Subscribe to transaction log messages that match a log filter. | +| [signatureSubscribe](/docs/reference/signature-subscribe) | Subscribe to status notifications for one transaction signature. | + +**Cluster** + +| Subscription Type | Description | +| ----------------------------------------------------------------------- | -------------------------------------------------------------------- | +| [rootSubscribe](/docs/reference/root-subscribe) | Subscribe to notifications when the validator sets a new root slot. | +| [slotSubscribe](/docs/reference/slot-subscribe) | Subscribe to notifications when the validator processes a new slot. | + # What are WebSockets and how do they differ from HTTP? WebSocket is a bidirectional communication protocol that maintains a network connection between a server and a client. Unlike HTTP, with WebSocket you don't need to continuously make requests when you want information. diff --git a/content/docs.yml b/content/docs.yml index db0cc8e52..a37dc997b 100644 --- a/content/docs.yml +++ b/content/docs.yml @@ -565,6 +565,29 @@ navigation: path: >- api-reference/websockets/subscription-api-endpoints/monadlogs.mdx slug: subscription-api-endpoints + - section: Solana Subscription API Endpoints + path: >- + api-reference/websockets/solana-subscription-api-endpoints/solana-subscription-api-endpoints.mdx + contents: + - page: accountSubscribe + path: >- + api-reference/websockets/solana-subscription-api-endpoints/account-subscribe.mdx + - page: programSubscribe + path: >- + api-reference/websockets/solana-subscription-api-endpoints/program-subscribe.mdx + - page: logsSubscribe + path: >- + api-reference/websockets/solana-subscription-api-endpoints/logs-subscribe.mdx + - page: signatureSubscribe + path: >- + api-reference/websockets/solana-subscription-api-endpoints/signature-subscribe.mdx + - page: rootSubscribe + path: >- + api-reference/websockets/solana-subscription-api-endpoints/root-subscribe.mdx + - page: slotSubscribe + path: >- + api-reference/websockets/solana-subscription-api-endpoints/slot-subscribe.mdx + slug: solana-subscription-api-endpoints slug: websockets - section: Yellowstone gRPC