KING BON
← Journal

·3 min read

Adding Solana wallet support to an existing web app

You do not need to rebuild your app to go on-chain. Connecting a wallet, reading a balance and sending a transaction from a normal React front end.

Web3 / Solana / React

A common request isn’t “build a dApp from scratch” but “let our existing users connect a wallet”. Maybe that’s to verify they hold a token, accept a payment or show their on-chain balance. You can add that to a regular React app without rebuilding anything.

The pieces

Solana’s wallet adapter packages handle most of the work:

npm i @solana/web3.js @solana/wallet-adapter-base \
  @solana/wallet-adapter-react @solana/wallet-adapter-react-ui

Modern wallets such as Phantom and Solflare announce themselves to the page through the Wallet Standard, so you usually don’t need to list them by hand.

Wrap the app

import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
import '@solana/wallet-adapter-react-ui/styles.css';

const endpoint = import.meta.env.VITE_SOLANA_RPC; // use a dedicated RPC in production

export function SolanaProviders({ children }: { children: React.ReactNode }) {
  return (
    <ConnectionProvider endpoint={endpoint}>
      <WalletProvider wallets={[]} autoConnect>
        <WalletModalProvider>{children}</WalletModalProvider>
      </WalletProvider>
    </ConnectionProvider>
  );
}

Wrap only the parts of the app that need it. The rest of your site doesn’t have to load any Web3 code.

Connect and read a balance

import { WalletMultiButton } from '@solana/wallet-adapter-react-ui';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';

function Balance() {
  const { connection } = useConnection();
  const { publicKey } = useWallet();
  const [sol, setSol] = useState<number | null>(null);

  useEffect(() => {
    if (!publicKey) return setSol(null);
    connection.getBalance(publicKey).then((l) => setSol(l / LAMPORTS_PER_SOL));
  }, [publicKey, connection]);

  return (
    <>
      <WalletMultiButton />
      {sol !== null && <p>{sol.toFixed(3)} SOL</p>}
    </>
  );
}

Send a transaction

const { publicKey, sendTransaction } = useWallet();

const tx = new Transaction().add(
  SystemProgram.transfer({ fromPubkey: publicKey!, toPubkey: recipient, lamports: 0.01 * LAMPORTS_PER_SOL }),
);
const signature = await sendTransaction(tx, connection);
await connection.confirmTransaction(signature, 'confirmed');

The wallet shows the user exactly what they’re signing. Your app never touches their private key.

Linking a wallet to an account

If your app has its own user accounts, don’t trust a wallet address sent from the browser. Have the server issue a one-time message, ask the wallet to sign it (signMessage), and verify the signature on the server before linking the address to the user. That proves they control the wallet.

Things to plan for

  • Use devnet while building. Free test SOL, no real money at risk.
  • Use a proper RPC provider in production. The public endpoint is rate-limited.
  • Design for “pending”. Transactions take a moment and can fail. Show clear states for waiting, confirmed and failed, with a link to a block explorer.
  • Mobile is different. On phones, users often open your site inside the wallet’s own browser. Test that flow early.

Going on-chain can be a feature you add, not a rewrite.