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 legacyTransactionandVersionedTransaction.
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-svmversion 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
Sponsor for an end user
To sponsor a transaction signed by an end user’s wallet, pass that user’suserId. 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:Related
signTransaction()- Sign a transaction (acceptssponsor: truefor a one-step flow)getSponsorAddress()- Read the sponsor address to build transactions that name it as fee payer- SVM Server-Controlled Sponsorship - Build and validate the transaction on your backend, then sponsor it for a user
- SVM Gas Sponsorship guide - Full guide on SVM gas sponsorship approaches