Skip to main content

Recommended: JavaScript SDK with React Hooks

For new React apps, we recommend the JavaScript SDK with React Hooks (@dynamic-labs-sdk/react-hooks) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the React quickstart (JavaScript SDK) to get started.
This is a React-only guide.
Looking for a simpler solution? If you’re using Dynamic’s embedded wallets, check out SVM Gas Sponsorship - a built-in feature that automatically sponsors gas fees with just a toggle in the dashboard.

Introduction

In this guide, we’ll show you how to create Solana transactions where a fee payer wallet pays the gas fees instead of your users. We achieve this by partially signing the transaction on the server and sending it to the client for final signing.

Getting Started

Setting up the Project

We’ll use Next.js for this example so the frontend and API routes stay in one codebase. Create the project with create-next-app, then follow the React Quickstart Custom setup path and enable Solana (SVM) only (no Wagmi). In the Dynamic dashboard, turn on Solana under Chains & Networks and add your dev origin under SecurityAllowed Origins. If you already have a Next.js app, add the Dynamic React SDK using the same quickstart.

Setting Up the Fee Payer Wallet

You’ll need a wallet that will pay for gas fees on behalf of your users:
  1. Create a Solana wallet and add some funds to it (for paying gas fees)
  2. Add its private key (string format) to your .env.local file:
.env.local
Never share your private key or commit it to your code repository. Always use environment variables and add them to your .gitignore.

Server Implementation

Creating the API Route

Now we’ll create an API route that will prepare partially-signed transactions. Create a file at app/api/gas/route.ts:
app/api/gas/route.ts

How It Works

Our API route:
  1. Receives details about the transfer (who’s sending, receiving, and how much)
  2. Creates a transaction with the instructions
  3. Sets our server wallet as the fee payer
  4. Partially signs the transaction with the fee payer wallet
  5. Returns the transaction to the frontend

Client Implementation

Creating the Frontend Component

Now let’s create a simple UI for users to send tokens without paying gas. Create app/components/Send.tsx:
app/components/Send.tsx
For styling, create the Send.css file and you can find the styles we used here.

Using the Component

Finally, add the component to your main page in app/page.tsx:
app/page.tsx

Conclusion

Congratulations! You’ve successfully implemented gasless transactions on Solana using Dynamic’s SDK. This approach creates a superior user experience by allowing your users to perform transactions without worrying about gas fees.

Next Steps

Consider implementing rate limiting or additional verification to protect your fee payer wallet from abuse. To get the complete source code, check out our GitHub repository.
Last modified on June 25, 2026