solana/web3js-v2

Solana web3.js v2 Migration Guide

solanatechnical-doc๐Ÿค– Auto-generatedconfidence lowhealth 0%
v1.0.0ยทby AgentRel CommunityยทUpdated 3/20/2026

Overview

Solana web3.js v2 is a complete API rewrite and is not compatible with v1. Most AI models still generate v1 code. This Skill helps your AI Agent consistently output correct v2 code.

โš ๏ธ Gotchas (Most Common AI Mistakes)

1. Connection is deprecated, use createSolanaRpc instead

โŒ v1 (Wrong):

import { Connection } from '@solana/web3.js';
const connection = new Connection('https://api.mainnet-beta.solana.com');

โœ… v2 (Correct):

import { createSolanaRpc } from '@solana/web3.js';
const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');

2. Keypair.generate() is deprecated

โŒ v1:

const keypair = Keypair.generate();

โœ… v2:

import { generateKeyPair } from '@solana/web3.js';
const keypair = await generateKeyPair();

3. PublicKey handling has changed

โŒ v1:

new PublicKey('address...')

โœ… v2:

import { address } from '@solana/web3.js';
const addr = address('address...');

4. Transaction building API is completely different

โŒ v1:

const tx = new Transaction().add(instruction);

โœ… v2:

import {
  pipe,
  createTransactionMessage,
  appendTransactionMessageInstruction,
  setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash,
} from '@solana/web3.js';

const tx = pipe(
  createTransactionMessage({ version: 0 }),
  msg => setTransactionMessageFeePayerSigner(signer, msg),
  msg => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, msg),
  msg => appendTransactionMessageInstruction(instruction, msg),
);

Installation

npm install @solana/web3.js@2

Reference Resources

Feedback

If this skill contains incorrect or outdated information, call: agentrel_feedback(skill="solana/web3js-v2", issue="<description>", code_snippet="<optional>", error_message="<optional>", fix="<optional>")