Sol.College

Full lesson

wallet-adapter

Modular TypeScript wallet adapters and components for Solana applications.

Original
anza-xyz/wallet-adapter
SuperStack fork
Blockchains/wallet-adapter @ 5f33bc6
Stars
2,032
Last push (original)
2026-10-06
Languages
TypeScript, CSS, JavaScript, HTML
Detected stack
Next.jsweb3.js
Categories
Wallets & Identity
Licence
Apache-2.0
Homepage
https://anza-xyz.github.io/wallet-adapter/

Architecture

146 source files. By extension: .ts ×107, .tsx ×38, .js ×1.

Top-level directorySource files
packages146

Dapp: deploying

This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/wallet-adapter/, once it is deployed and checked on devnet. Until then, run it locally with the commands below.

Key code, explained

Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.

anza-xyz/wallet-adapter · packages/core/base/src/adapter.ts L97–119 @ 5f33bc6 · Apache-2.0 · original
    abstract sendTransaction(        transaction: TransactionOrVersionedTransaction<this['supportedTransactionVersions']>,        connection: Connection,        options?: SendTransactionOptions    ): Promise<TransactionSignature>;     protected async prepareTransaction(        transaction: Transaction,        connection: Connection,        options: SendOptions = {}    ): Promise<Transaction> {        const publicKey = this.publicKey;        if (!publicKey) throw new WalletNotConnectedError();         transaction.feePayer = transaction.feePayer || publicKey;        transaction.recentBlockhash =            transaction.recentBlockhash ||            (                await connection.getLatestBlockhash({                    commitment: options.preflightCommitment,                    minContextSlot: options.minContextSlot,                })            ).blockhash;
  1. Line 97 abstract sendTransaction(: Submits the signed transaction to the cluster.
  2. Line 115 await connection.getLatestBlockhash({: Fetches a recent blockhash. Transactions expire if it gets too old.
anza-xyz/wallet-adapter · packages/starter/example/src/components/SendTransaction.tsx L1–24 @ 5f33bc6 · Apache-2.0 · original
import { Button } from '@mui/material';import { useConnection, useWallet } from '@solana/wallet-adapter-react';import type { TransactionSignature } from '@solana/web3.js';import { PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js';import React, { useCallback, type FC } from 'react';import { useNotify } from './useNotify'; export const SendTransaction: FC = () => {    const { connection } = useConnection();    const { publicKey, sendTransaction } = useWallet();    const notify = useNotify();     const onClick = useCallback(async () => {        let signature: TransactionSignature | undefined = undefined;        try {            if (!publicKey) throw new Error('Wallet not connected!');             const {                context: { slot: minContextSlot },                value: { blockhash, lastValidBlockHeight },            } = await connection.getLatestBlockhashAndContext();             const transaction = new Transaction({                feePayer: publicKey,
  1. Line 10 const { publicKey, sendTransaction } = useWallet();: Submits the signed transaction to the cluster.
  2. Line 21 } = await connection.getLatestBlockhashAndContext();: Fetches a recent blockhash. Transactions expire if it gets too old.
anza-xyz/wallet-adapter · packages/starter/example/src/components/SendLegacyTransaction.tsx L25–48 @ 5f33bc6 · Apache-2.0 · original
            } = await connection.getLatestBlockhashAndContext();             const message = new TransactionMessage({                payerKey: publicKey,                recentBlockhash: blockhash,                instructions: [                    {                        data: Buffer.from('Hello, from the Solana Wallet Adapter example app!'),                        keys: [],                        programId: new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),                    },                ],            });            const transaction = new VersionedTransaction(message.compileToLegacyMessage());             signature = await sendTransaction(transaction, connection, { minContextSlot });            notify('info', 'Transaction sent:', signature);             await connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature });            notify('success', 'Transaction successful!', signature);        } catch (error: any) {            notify('error', `Transaction failed! ${error?.message}`, signature);        }    }, [publicKey, supportedTransactionVersions, connection, sendTransaction, notify]);
  1. Line 25 } = await connection.getLatestBlockhashAndContext();: Fetches a recent blockhash. Transactions expire if it gets too old.
  2. Line 40 signature = await sendTransaction(transaction, connection, { minContextSlot });: Submits the signed transaction to the cluster.

How to run, build and test

These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.

DirectoryCommandRuns
.npm run buildturbo run build --concurrency=100%
.npm run testturbo run test --concurrency=100%
.npm run lintturbo run lint --concurrency=100%
.npm run deploypnpm run deploy:docs && pnpm run deploy:example

What you could build from it

Used in lessons