For AI agents: a documentation index is available at /llms.txt. A markdown version of this page is available at the same URL with .md appended (or via Accept: text/markdown).
Skip to main content

Integrate Solana Pay with Embedded Wallets

embedded walletsplug and playwebsolanasolana payreacted25519MetaMask Developer Relations | November 15, 2025

The Web3Auth by MetaMask, Embedded Wallet SDK enables users to sign in with familiar web2 socials by using Shamir's Secret Sharing Multi-Party Computation (MPC) to ensure the wallet key is distributed and non-custodial.

This tutorial demonstrates how to integrate Solana Pay with the Embedded Wallet SDK to create a seamless payment experience for your users. By combining Embedded Wallets' familiar web2 social sign-in with Solana Pay's QR code functionality, you can enable users to make payments directly from their social sign-in wallets.

The Embedded Wallet SDK social sign-in allows users to:

  • Sign in using familiar web2 social providers (such as Google and Apple).
  • Generate Solana Pay QR codes for transactions.
  • Make payments using their embedded wallet.

This tutorial follows the implementation demonstrated in the following live stream:

info

A complete implementation example is available on GitHub.

Step 1: Set up the dashboard​

Follow these steps to set up and configure your Embedded Wallets (Web3Auth) dashboard:

  1. Sign up for a free account on the Embedded Wallets dashboard.
  2. Create a new project.
  3. Copy your Client ID from the dashboard. This ID is crucial for initializing the SDK.
  4. Navigate to Chains & Networks and enable Solana, Solana Devnet, and Solana Testnet. Ensure all the RPC URLs are configured.
tip

See the Embedded Wallets dashboard documentation for more information. You can explore other dashboard features, including custom verifiers, whitelabeling, and analytics.

Step 2: Install dependencies​

Install the following dependencies in your project:

npm install @web3auth/modal @solana/kit @solana/react-hooks @solana/pay
note
  • @web3auth/modal: Enables the embedded wallet integration with social logins.
  • @solana/kit: Enables interacting with the Solana blockchain, such as fetching balances and creating addresses.
  • @solana/react-hooks: Required peer dependency for the Embedded Wallets React Solana hooks (@web3auth/modal/react/solana).
  • @solana/pay: The core Solana Pay protocol library. Version 1.x uses @solana/kit types, so recipients and references are Address values and amounts are plain numbers.

Step 3: Integrate the Embedded Wallet SDK in React​

Use the @web3auth/modal SDK to integrate and manage Embedded Wallets in your React application.

3.1. Initialize the provider​

Wrap your application components with a Web3AuthProvider to configure the SDK with your Client ID, and a SolanaProvider so the Solana hooks can access the connected wallet:

src/main.tsx
import './index.css';

import ReactDOM from 'react-dom/client';
import { Web3AuthProvider } from '@web3auth/modal/react';
import { SolanaProvider } from '@web3auth/modal/react/solana';
import web3AuthContextConfig from './web3authContext';
import App from './App';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<Web3AuthProvider config={web3AuthContextConfig}>
<SolanaProvider>
<App />
</SolanaProvider>
</Web3AuthProvider>
);
src/web3authContext.tsx
import { WEB3AUTH_NETWORK } from '@web3auth/modal'
import { type Web3AuthContextConfig } from '@web3auth/modal/react'

// Dashboard Registration
const clientId =
'BFcLTVqWlTSpBBaELDPSz4_LFgG8Nf8hEltPlf3QeUG_88GDrQSw82fSjjYj5x4F3ys3ghMq8-InU7Azx7NbFSs' // get from https://developer.metamask.io

// Instantiate the SDK.
const web3AuthContextConfig: Web3AuthContextConfig = {
web3AuthOptions: {
clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
},
}

export default web3AuthContextConfig

3.2. Access wallet information and fetch user balance​

Access wallet information and user details using the Solana hooks:

src/components/getBalance.tsx
import { address } from '@solana/kit';
import { useSolanaWallet } from '@web3auth/modal/react/solana';
import { useState } from 'react';

export function Balance() {
const { accounts, rpc } = useSolanaWallet();
const [balance, setBalance] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

async function fetchBalance() {
if (!rpc || !accounts?.length) return;

setIsLoading(true);
setError(null);
try {
const { value } = await rpc.getBalance(address(accounts[0])).send();
setBalance(`${Number(value) / 1e9} SOL`);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to fetch balance.');
} finally {
setIsLoading(false);
}
}

return (
<div>
<h2>Balance</h2>
{balance && <div>{balance}</div>}
<button onClick={() => void fetchBalance()} type='button' className='card' disabled={isLoading}>
{isLoading ? 'Fetching...' : 'Fetch Balance'}
</button>
{error && <div className='error'>Error: {error}</div>}
</div>
);
}

Step 4: Integrate Solana Pay​

Solana Pay enables the generation of transaction requests, typically as QR codes, for direct payments from Solana wallets. Follow these steps to create and display Solana Pay QR codes for payments.

4.1. Import components​

Import the necessary components from the installed libraries:

import { address, generateKeyPairSigner } from '@solana/kit'
import { createQR, encodeURL } from '@solana/pay'
import { useSolanaWallet } from '@web3auth/modal/react/solana'

4.2. Generate QR codes​

The core of the Solana Pay integration involves creating a payment request URL and then rendering it as a QR code. First, define the following:

  • Recipient and amount: Define the recipient (an Address of the merchant/receiver) and the amount (a number representing the payment value in SOL, for example, 0.001).
  • Reference: Generate a unique reference for the payment. This acts as a unique identifier for the transaction.
  • Optional fields: Include label, message, and memo for enhanced user experience.

The following is an example implementation of a Solana Pay QR code generator:

src/components/solanaPay.tsx
import { address, generateKeyPairSigner } from '@solana/kit';
import { createQR, encodeURL } from '@solana/pay';
import { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { useSolanaWallet } from '@web3auth/modal/react/solana';

export function SolanaPay() {
const { accounts } = useSolanaWallet();
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [amountToSend, setAmountToSend] = useState(0);
const [showModal, setShowModal] = useState(false);
const [qrUrl, setQrUrl] = useState<string>('');
const qrRef = useRef<HTMLDivElement>(null);

const generateQrCode = async () => {
try {
if (!accounts?.[0]) {
setError('No wallet connected');
return;
}

setIsLoading(true);
setError(null);
// set the parameter of the transfer
const recipient = address(accounts[0]);
const amount = amountToSend;
// reference should be a unique ID for the payment
const reference = (await generateKeyPairSigner()).address;
// Label and message are optional. They will be shown in wallets when users scan it but won't show on chain
const label = 'MetaMask Embedded Wallet x Solana Pay Demo';
const message = 'Thanks for Trying Solana Pay!';
// memo is optional and will be included in the onchain transaction
const memo = 'Thanks for Trying Solana Pay!';
// create the URL
const url = encodeURL({
recipient,
amount,
reference,
label,
message,
memo,
});

setQrUrl(url.toString());
setShowModal(true);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to generate QR code');
} finally {
setIsLoading(false);
}
};
// Generate QR code when modal opens and URL is available
useEffect(() => {
if (showModal && qrUrl && qrRef.current) {
qrRef.current.innerHTML = '';
try {
const qr = createQR(qrUrl, 300, 'white');
qr.append(qrRef.current);
} catch (err) {
setError('Failed to create QR code');
}
}
}, [showModal, qrUrl]);

const closeModal = () => {
setShowModal(false);
setQrUrl('');
setError(null);
};

return (
<>
<div>
<h2>Solana Pay QR</h2>
<div className='flex flex-col items-center gap-4'>
<input
type='number'
placeholder='Enter SOL amount'
onChange={(e) => setAmountToSend(Number(e.target.value))}
className='px-4 py-2 border rounded-lg text-black'
step='0.01'
min='0'
/>
<button
onClick={() => void generateQrCode()}
className='px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600'
disabled={isLoading || amountToSend <= 0}
>
{isLoading ? 'Generating...' : 'Generate Payment QR'}
</button>

{/* Error Display */}
{error && !showModal && (
<div className='text-red-500 text-sm mt-2'>
Error: {error}
</div>
)}
</div>
</div>
...

Testing and best practices​

Development environment​

  • Devnet for testing: Always develop and test on devnet or testnet. You can use the Solana Faucet to get test SOL for your new account.
  • Environment variables: Store your Client ID and other sensitive configuration in environment variables.

User experience​

  • User interface: For better user experience, display the QR code within a modal or a dedicated confirmation page, providing clear messages to the user.
  • Loading states: Implement proper loading states while generating QR codes and processing transactions.
  • Error handling: Provide clear error messages when transactions fail or when the user's wallet doesn't have sufficient balance.

Production readiness​

  • Tracking payments: Implement a server-side solution to track the unique payment reference and poll for transaction confirmation using websockets. This allows you to update your application's state and perform reconciliation in your database.
  • Production RPCs: For scalable production usage, use dedicated Solana RPC services from providers like Infura, as public RPCs may have rate limits.
  • Security: Validate all payment parameters server-side before processing transactions.

Next steps​