Commerce Kit is no longer maintainedCommerce Kit packages no longer receive updates or fixes. For new payment
integrations, use Solana Pay.
@solana-commerce/sdk package provides React hooks for building custom
Solana payment experiences. These hooks offer full control over SOL and SPL
token transfers with built-in state management, automatic retry logic, error
handling, and UI helpers.
Under the hood, the SDK uses TanStack Query for
caching and state management, @solana/kit for
Solana primitives, and works with @solana-commerce/connector
for wallet connection.
Installation
Provider Setup
ArcProvider
The ArcProvider is the root provider that initializes the Solana RPC client,
manages network configuration, and provides blockchain connectivity to all
hooks. It must wrap any components that use SDK hooks.
Props
config(ArcWebClientConfig) - Configuration object for the Arc clientchildren(ReactNode) - Child components that will have access to the hooksqueryClient(QueryClient, optional) - Custom TanStack Query client. If not provided, a default instance is created internally.
ArcWebClientConfig
Configuration for the Arc client that controls RPC connectivity and commitment
levels.
Required Fields
The provider automatically integrates with@solana-commerce/connector through
the useConnectorClient hook, so no explicit connector configuration is needed
when used within a ConnectorProvider.
Optional Fields
-
network('mainnet' | 'devnet' | 'testnet') - Solana network to connect to. Default:'mainnet'. -
rpcUrl(string) - Custom RPC endpoint URL. If not provided, uses public endpoints for the selected network. -
commitment('processed' | 'confirmed' | 'finalized') - Transaction confirmation level. Default:'confirmed'. -
debug(boolean) - Enables verbose console logging for debugging. Default:false. -
autoConnect(boolean) - Automatically connects to the wallet when the component mounts. Default:true. -
storage(Storage) - Custom storage adapter for persisting wallet preferences. Must implement:getItem(key: string): string | nullsetItem(key: string, value: string): voidremoveItem(key: string): void
window.localStoragewhen available (browser only). Use this for React Native (AsyncStorage) or custom SSR-safe storage.
Integration with ConnectorProvider
The provider integrates with ConnectorProvider from
@solana-commerce/connector. Always wrap your app with ConnectorProvider
before ArcProvider:
Core Hooks
useTransferSOL
Hook for transferring SOL with automatic retry logic, state management, and UI
helper functions. Built on TanStack Query for caching and request deduplication.
Signature
Parameters
initialToInput(string, optional) - Initial value for the recipient address input. Useful for pre-filling forms.initialAmountInput(string, optional) - Initial value for the amount input in SOL. Useful for pre-filling forms.
Return Value
Core Function
transferSOL- Initiates a SOL transfer. Returns a promise that resolves when the transaction is confirmed onchain.
State Properties
-
isLoading(boolean) -truewhile the transaction is being processed (signing, submitting, confirming). Use this for loading indicators and button states. -
error(Error | null) - Error object if the transaction failed at any stage.nullwhen no error. Errors include wallet rejections, insufficient balance, network failures, etc. -
data(TransferSOLResult | null) - Result object when transaction succeeds. Contains signature, addresses, amounts, and blockchain metadata.nullbefore first successful transfer. -
reset(() => void) - Resets the mutation state, clearingerroranddata. Useful for retry flows or resetting forms after completion.
UI Helper Properties & Methods
The hook provides built-in state management for form inputs:-
toInput/setToInput- Controlled state for recipient address input field -
amountInput/setAmountInput- Controlled state for amount input field (in SOL, not lamports) -
handleToInputChange- Pre-bound onChange handler for recipient input:<input onChange={handleToInputChange} /> -
handleAmountInputChange- Pre-bound onChange handler for amount input:<input onChange={handleAmountInputChange} /> -
transferFromInputs- Convenience method that transfers SOL using the currenttoInputandamountInputvalues. Automatically converts amount from SOL to lamports. -
handleSubmit- Form submission handler that callstransferFromInputs()and prevents default form behavior. Use with<form onSubmit={handleSubmit}>.
Options
-
to(required) - Recipient Solana address. Can be a stringorAddresstype from@solana/kit. -
amount(required) - Transfer amount in lamports (not SOL). Must be abigint. UseBigInt()or literal notation:1_000_000_000n= 1 SOL. -
from(optional) - Sender address. If not provided, uses the address from the connected wallet. Required only for advanced use cases (e.g., signing for a different account).
Result
The result includes transaction metadata including transfer details and the transaction signature:Internal Architecture
Transaction Builder: The hook uses a shared transaction builder that:- Fetches fresh blockhashes for each transaction
- Builds optimized transaction messages with minimal fees
- Signs transactions using the connected wallet
- Submits and confirms transactions in a single flow
- Sender’s balance (
fromaddress) - Recipient’s balance (
toaddress)
useArcClient)
automatically refetch and update without manual intervention.
Precise Amount Conversion: When using transferFromInputs(), the amount is
converted from SOL to lamports using string-based arithmetic to avoid
floating-point precision errors. The conversion:
- Validates input format (rejects negative, invalid numbers)
- Handles up to 9 decimal places (1 lamport = 0.000000001 SOL)
- Truncates or pads fractional values as needed
- Throws descriptive errors for invalid inputs
useTransferToken
Like useTransferSOL, this hook is used for transferring SPL tokens. In
addition to handling transfers, the hook also handlesautomatic Associated Token
Account (ATA) creation when needed.
Signature
Parameters
initialMintInput(string, optional) - Initial token mint address. Useful for fixed-token transfers.initialToInput(string, optional) - Initial recipient address.initialAmountInput(string, optional) - Initial amount in token’s base units (considering decimals).
Return Value
useTransferSOL but includes an additional
mintInput state for token selection.
Options
Required Fields
-
mint- SPL token mint address. For example:- USDC:
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' - USDT:
'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'
- USDC:
-
to- Recipient’s wallet address (not their token account). The hook automatically derives the correct Associated Token Account. -
amount- Transfer amount in the token’s smallest unit. Must account for token decimals:- USDC (6 decimals):
1_000_000n= 1 USDC - SOL-wrapped tokens (9 decimals):
1_000_000_000n= 1 token
- USDC (6 decimals):
Optional Fields
-
from- Sender’s wallet address. Defaults to connected wallet. -
createAccountIfNeeded(default:true) - If the recipient doesn’t have a token account for this mint, automatically create it as part of the transaction. Whenfalse, the transfer will fail if the recipient account doesn’t exist. Note: Creating a token account costs a refundable rent deposit of about 0.0015 SOL on mainnet (as of October 2026). This is paid by the sender. -
retryConfig- Configuration for automatic retry on blockhash expiration. See Retry Configuration.
Result
The result includes transaction metadata including transfer details and the transaction signature:Retry Configuration
The hook includes sophisticated retry logic for handling blockhash expiration, which commonly occurs during network congestion.-
maxAttempts- Maximum number of transaction attempts. Each attempt fetches a fresh blockhash. Default:3. -
baseDelay- Delay in milliseconds before the first retry. Default:1000(1 second). -
backoffMultiplier- Exponential backoff multiplier. Each retry waitsbaseDelay * (backoffMultiplier ^ attemptNumber)milliseconds.1= linear backoff (1s, 1s, 1s)1.5= exponential backoff (1s, 1.5s, 2.25s)2= aggressive exponential (1s, 2s, 4s)
- First Attempt: Transaction is built with current blockhash and submitted
- Blockhash Expires: If the blockhash becomes stale before confirmation, Solana rejects the transaction
- Automatic Retry: Hook detects expiration, fetches a fresh blockhash, rebuilds the transaction, and resubmits
- Exponential Backoff: Each retry waits longer to avoid network congestion
- Final Failure: After
maxAttempts, throwsBlockhashExpirationErrorwith context
- Non-blockhash errors (insufficient funds, invalid accounts, etc.) throw immediately without retrying
- Only blockhash expiration errors trigger the retry mechanism
Internal Architecture
ATA Management:- Derives Associated Token Accounts deterministically using
findAssociatedTokenPda(Note: only the Token Program is supported at this time) - Checks if sender has a token account (fails fast if sender doesn’t hold the token)
- Checks if recipient has a token account (creates if needed and
createAccountIfNeeded: true) - Account checks only run on the first attempt to avoid redundant RPC calls during retries
- Sender’s token balance for this mint
- Recipient’s token balance for this mint
- Related account data
useArcClient
Hook for accessing the underlying Solana RPC client, wallet state, and network
configuration. This is a lower-level hook for advanced use cases that need
direct RPC access.
Signature
Return Value
State
TheArcClientSnapshot extends the ArcWebClient which provides access to:
- wallet state (address, signer, available wallets, features, and wallet status)
- network configuration (RPC endpoint,
isMainnet/isDevnet/isTestnet,canAirdropandclusterInfo.name)