Skip to main content

Function Signature

Description

Sends an unsigned Solana transaction to Dynamic’s gas sponsorship endpoint (/solana/sponsorTransaction), which replaces the fee payer with the sponsor’s address. The returned transaction has the sponsor as fee payer and should be passed to signTransaction() instead of the original. Gas sponsorship must be enabled for your environment in the Dynamic Console before calling this method.
For most use cases, pass sponsor: true to signTransaction() instead of calling sponsorTransaction() directly. Use this method when you need to inspect or modify the sponsored transaction before signing.

Parameters

Required Parameters

  • transaction (VersionedTransaction | Transaction) — The unsigned Solana transaction. Supports both legacy Transaction and VersionedTransaction.

Optional Parameters

  • userId (string) — The end user the transaction is for. Required when the signing wallet is that user’s wallet rather than one of your own server wallets. The signing wallet must belong to this user in your environment, and the request is rejected otherwise. Omit it to sponsor transactions signed by your own server wallets. Requires @dynamic-labs-wallet/node-svm version 1.1.64 or later.
  • traceContext (TraceContext) — Distributed tracing context for observability.

Returns

Promise<VersionedTransaction> — The sponsored transaction with the gas sponsor set as fee payer and the sponsor’s signature in place. The endpoint always returns a versioned transaction, whichever type you pass in.

Example

To sponsor a transaction signed by an end user’s wallet, pass that user’s userId. When your environment restricts sponsorship to server-side requests, this is how your backend sponsors transactions for users. The SVM Server-Controlled Sponsorship recipe shows the full flow.

Error Handling

The method throws when sponsorship is unavailable or not enabled:
Last modified on November 5, 2026