Sol.College

Full lesson

solana-web3.js

Solana JavaScript SDK

What it does

From the project README:

This repository is a pnpm workspace containing `@solana/web3.js` and the tooling that ships alongside it. Each package is versioned and published independently; the root package is private and exists only to orchestrate installs and scripts across the workspace.
Original
solana-foundation/solana-web3.js
SuperStack fork
Blockchains/solana-web3.js @ 648516f
Stars
2,783
Last push (original)
2026-11-02
Languages
TypeScript, Just, JavaScript, Shell, CSS
Detected stack
@solana/kitNext.jsweb3.js
Categories
Infrastructure & Tooling
Licence
MIT
Homepage
https://solana-foundation.github.io/solana-web3.js/

Architecture

165 source files. By extension: .ts ×130, .tsx ×35.

Top-level directorySource files
packages144
examples21

Dapp: deploying

This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/solana-web3-js/, 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.

solana-foundation/solana-web3.js · packages/web3.js/src/publickey.ts L289–312 @ 648516f · MIT · original
  /**   * Find a valid program address   *   * Valid program addresses must fall off the ed25519 curve.  This function   * iterates a nonce until it finds one that when combined with the seeds   * results in a valid program address.   *   * @throws `SolanaError` with   * `SOLANA_ERROR__ADDRESSES__MAX_NUMBER_OF_PDA_SEEDS_EXCEEDED` from   * `@solana/errors` if the supplied seeds exceed the PDA count limit.   * @throws `SolanaError` with   * `SOLANA_ERROR__ADDRESSES__MAX_PDA_SEED_LENGTH_EXCEEDED` from   * `@solana/errors` if any supplied seed exceeds the PDA seed-length limit.   * @throws `SolanaError` with   * `SOLANA_ERROR__ADDRESSES__FAILED_TO_FIND_VIABLE_PDA_BUMP_SEED` from   * `@solana/errors` if no viable bump seed exists.   */  static async findProgramAddress(    seeds: Array<Uint8Array | ReadonlyUint8Array>,    programId: PublicKey,  ): Promise<[PublicKey, number]> {    const [derivedAddress, nonce] = await getProgramDerivedAddress({      programAddress: programId.toBase58(),      seeds,
  1. Line 304 * `@solana/errors` if no viable bump seed exists.: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
  2. Line 306 static async findProgramAddress(: Derives a PDA from seeds and the program ID and returns the address with its canonical bump.
solana-foundation/solana-web3.js · packages/wallet-adapter/src/__tests__/web3js-test.tsx L385–408 @ 648516f · MIT · original
          authorizedPubkey: payer,          noncePubkey: payer,        }),      };    transaction.feePayer = undefined;    transaction.recentBlockhash = undefined;    const getLatestBlockhash = vi.fn(async () => ({      blockhash,      lastValidBlockHeight: 42n,    }));    const sendRawTransaction = vi.fn(async () =>      getBase58Decoder().decode(SIGNATURE),    );    await owner.sendTransaction(      transaction,      {getLatestBlockhash, sendRawTransaction} as unknown as Connection,      {        minContextSlot: 123n,        preflightCommitment: 'confirmed',      },    );    if (lifetime === 'draft') {      expect(getLatestBlockhash).toHaveBeenCalledExactlyOnceWith({        commitment: 'confirmed',
  1. Line 391 const getLatestBlockhash = vi.fn(async () => ({: Fetches a recent blockhash. Transactions expire if it gets too old.
  2. Line 398 await owner.sendTransaction(: Submits the signed transaction to the cluster.
solana-foundation/solana-web3.js · packages/wallet-adapter/src/__tests__/e2e/app-live-test.tsx L265–287 @ 648516f · MIT · original
    await connectTo(result, 'Legacy-only wallet');    const sender = new PublicKey(legacyOnlySigner.address);    const versioned = new VersionedTransaction(      new TransactionMessage({        instructions: [          SystemProgram.transfer({            fromPubkey: sender,            lamports: 1n,            toPubkey: sender,          }),        ],        payerKey: sender,        recentBlockhash: (await connection.getLatestBlockhash()).blockhash,      }).compileToV0Message(),    );    await expect(      result.current.sendTransaction(versioned, connection),    ).rejects.toBeInstanceOf(WalletSendTransactionError);    await act(() => result.current.disconnect());    await expect(      result.current.sendTransaction(new Transaction(), connection),    ).rejects.toBeInstanceOf(WalletNotConnectedError);  });
  1. Line 277 recentBlockhash: (await connection.getLatestBlockhash()).blockhash,: Fetches a recent blockhash. Transactions expire if it gets too old.
  2. Line 281 result.current.sendTransaction(versioned, connection),: Submits the signed transaction to the cluster.
solana-foundation/solana-web3.js · examples/wallet-adapter/components/SendV1Transaction.tsx L13–36 @ 648516f · MIT · original
  const {connection} = useConnection();  const {publicKey, sendTransaction, supportedTransactionVersions} =    useWallet();  const notify = useNotify();  const supported = supportsTransactionVersion(supportedTransactionVersions, 1);   const onClick = async () => {    let signature: TransactionSignature | undefined;    try {      if (!publicKey) throw new Error('Wallet not connected!');      if (!supported)        throw new Error("Wallet doesn't support v1 transactions!");       const {        context: {slot: minContextSlot},        value: {blockhash, lastValidBlockHeight},      } = await connection.getLatestBlockhashAndContext();       const message = new TransactionMessage({        instructions: [selfTransferInstruction(publicKey)],        payerKey: publicKey,        recentBlockhash: blockhash,      });      // v1 carries the compute budget in the message. Unset limits resolve to
  1. Line 14 const {publicKey, sendTransaction, supportedTransactionVersions} =: Submits the signed transaction to the cluster.
  2. Line 29 } = await connection.getLatestBlockhashAndContext();: Fetches a recent blockhash. Transactions expire if it gets too old.

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
packages/web3.jsnpm run devNODE_ENV=development rollup -c --watch
examples/wallet-adapternpm run devnext dev
examples/wallet-adapternpm run buildnext build

What you could build from it

Used in lessons