Skip to main content

Send Transaction

Send and broadcast Solana transactions using a user’s embedded wallet. MoonKey handles transaction signing and submission to the Solana network.

Overview

Sending transactions on Solana enables:
  • SOL transfers: Send native SOL tokens between addresses
  • SPL token transfers: Transfer fungible tokens (SPL tokens)
  • Program interactions: Execute instructions on Solana programs
  • NFT operations: Mint, transfer, or burn NFTs
MoonKey uses @solana/web3.js for transaction construction. Transactions are serialized, signed, and broadcast to the network automatically.

React SDK

To send a transaction, use the sendTransaction method from the useSendTransaction hook:

Parameters

Transaction
required
The Solana transaction to send. Must be a Transaction object from @solana/web3.js.Example:
Connection
required
The Solana RPC connection to use for broadcasting the transaction.Example:

Options Object

The second parameter is an optional configuration object:
object
Configuration for the transaction confirmation modal.

Hook Callbacks

(result: { signature: string }) => void
Callback executed after successful transaction. Receives the transaction signature.
(error: Error) => void
Callback executed if transaction fails or user cancels.

Returns

string
The transaction signature (base58 encoded string).

Complete Examples

SOL Transfer

SPL Token Transfer

Program Interaction

Transaction Construction

Basic Transaction Setup

Multiple Instructions

RPC Endpoints

Use appropriate RPC endpoints for different networks:
For production applications, use a dedicated RPC provider like Helius, QuickNode, or Alchemy for better reliability and rate limits.

Install Dependencies

UI Customization

Customize the transaction confirmation modal:

Hide Modal

Hiding the modal removes the user’s ability to review the transaction before signing. Only use this for trusted operations or after obtaining explicit user consent.

Error Handling

Handle common transaction errors:

Best Practices

Always verify sufficient balance:
Always fetch a recent blockhash before sending:
Validate recipient addresses before sending:
Wait for transaction confirmation:
Implement retry logic for network issues:
Choose the right network for your use case:

Troubleshooting

Blockhashes expire quickly on Solana (~60 seconds):
Check both SOL balance and required amount:
Transaction simulation can fail for various reasons:
Use appropriate timeouts and retry logic:

Sign Transaction

Sign transactions without broadcasting

Sign Message

Sign messages with Solana wallet

Solana Web3.js

Official Solana JavaScript library

SPL Token

SPL Token program documentation

Next Steps