Overview
This guide shows how to send Solana transactions using CDP React Hooks or the React Component. Sending a Solana transaction is a two-step process.1. Build a transaction
Use@solana/web3.js
to construct Solana transactions. The example below creates a createAndEncodeTransaction
helper function that builds a simple transfer transaction and returns it as a base64-encoded string:
buildTransaction.ts
2. Send a transaction
Once you’ve built your transaction, you can send it using either React hooks or the React component.Option A: Using React hooks
UseuseSendSolanaTransaction
for programmatic control. This hook signs the transaction with the user’s embedded wallet and broadcasts it to the Solana network, returning the transaction signature.
The example below uses the createAndEncodeTransaction
helper from Step 1 to build the transaction:
sendTransactionUsingHooks.tsx
Option B: Using React component
UseSendSolanaTransactionButton
for a pre-built UI button. This component handles the entire flow (signing and broadcasting) with built-in loading states and error handling.
The example below uses the createAndEncodeTransaction
helper from Step 1 to build the transaction. It uses useMemo
to cache the transaction so it’s only rebuilt when the Solana address changes, improving performance:
sendTransactionUsingComponent.tsx
What to read next
- Signing: Learn how to sign Solana messages and transactions without broadcasting
- React Hooks: Explore all available CDP hooks for embedded wallets
- Quickstart: Get started with embedded wallets in under 10 minutes