@solana/web3-compat 0.0.5 → 0.0.6-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +84 -28
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -9,20 +9,29 @@ The goal of this release is **zero breaking changes** for applications that only
9
9
  touch the subset of web3.js APIs listed below. There will be future releases that slowly
10
10
  implement breaking changes as they move over to Kit primitives and intuitions.
11
11
 
12
- ## Installation
12
+ ## Migrating from `@solana/web3.js`
13
+
14
+ The migration process is straightforward and can be done incrementally:
15
+
16
+ ### Install the compatibility package
13
17
 
14
18
  ```bash
15
19
  pnpm add @solana/web3-compat
16
20
  ```
17
21
 
18
- Your project must also have valid Kit peer dependencies (`@solana/kit`,
19
- `@solana/client`, etc.).
22
+ Make sure you also have the required Kit peer dependencies:
23
+
24
+ ```bash
25
+ pnpm add @solana/kit @solana/client
26
+ ```
27
+
28
+ ### Update your imports
20
29
 
21
- ## Usage
30
+ Replace your web3.js imports with the compatibility layer. Both import styles are supported:
22
31
 
23
- In Phase 0, you should be able to leave your web3.js code as-is.
32
+ #### Named imports (TypeScript/ES6 style)
24
33
 
25
- The compatibility layer mirrors the web3.js entry points:
34
+ **Before:**
26
35
 
27
36
  ```ts
28
37
  import {
@@ -30,33 +39,71 @@ import {
30
39
  Keypair,
31
40
  PublicKey,
32
41
  SystemProgram,
42
+ Transaction,
43
+ sendAndConfirmTransaction,
44
+ } from "@solana/web3.js";
45
+ ```
46
+
47
+ **After:**
48
+
49
+ ```ts
50
+ import {
51
+ Connection,
52
+ Keypair,
53
+ PublicKey,
54
+ SystemProgram,
55
+ Transaction,
33
56
  sendAndConfirmTransaction,
34
57
  } from "@solana/web3-compat";
58
+ ```
59
+
60
+ #### Namespace imports
61
+
62
+ **Before:**
35
63
 
36
- const connection = new Connection(
37
- "https://api.mainnet-beta.solana.com",
38
- "confirmed"
64
+ ```js
65
+ const solanaWeb3 = require("@solana/web3.js");
66
+ const connection = new solanaWeb3.Connection(
67
+ "https://api.mainnet-beta.solana.com"
39
68
  );
69
+ ```
70
+
71
+ **After:**
72
+
73
+ ```js
74
+ const solanaWeb3 = require("@solana/web3-compat");
75
+ const connection = new solanaWeb3.Connection(
76
+ "https://api.mainnet-beta.solana.com"
77
+ );
78
+ ```
79
+
80
+ Or with ES6 modules:
81
+
82
+ ```ts
83
+ import * as solanaWeb3 from "@solana/web3-compat";
84
+ ```
40
85
 
41
- const payer = Keypair.generate();
42
- const recipient = Keypair.generate().publicKey;
86
+ ### (Optional): Leverage Kit features
43
87
 
44
- const transferIx = SystemProgram.transfer({
45
- fromPubkey: payer.publicKey,
46
- toPubkey: recipient,
47
- lamports: 1_000_000,
48
- });
88
+ You can gradually adopt Kit primitives alongside the compatibility layer using bridge helpers:
49
89
 
50
- const transaction = new Transaction().add(transferIx);
51
- transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
52
- transaction.feePayer = payer.publicKey;
90
+ ```ts
91
+ import { toAddress, toPublicKey, toKitSigner } from "@solana/web3-compat";
92
+
93
+ // Convert between web3.js and Kit types
94
+ const web3PublicKey = new PublicKey("11111111111111111111111111111111");
95
+ const kitAddress = toAddress(web3PublicKey);
53
96
 
54
- await sendAndConfirmTransaction(connection, transaction, [payer]);
97
+ // Convert back if needed
98
+ const backToWeb3 = toPublicKey(kitAddress);
55
99
  ```
56
100
 
57
- Under the hood every RPC call goes through Kit via `@solana/client`, but currently
58
- the surface area, return types, and error semantics stay aligned with
59
- `@solana/web3.js`.
101
+ ### Migration checklist
102
+
103
+ - [ ] Install `@solana/web3-compat` and Kit dependencies
104
+ - [ ] Update import statements from `@solana/web3.js` to `@solana/web3-compat`
105
+ - [ ] Test your application
106
+ - [ ] Keep legacy `@solana/web3.js` for any unimplemented methods (see limitations below)
60
107
 
61
108
  ## Implemented in Phase 0
62
109
 
@@ -80,16 +127,25 @@ the surface area, return types, and error semantics stay aligned with
80
127
  - Re‑exports of all Web3 primitives (`PublicKey`, `Keypair`, `Transaction`,
81
128
  `VersionedTransaction`, `TransactionInstruction`, etc)
82
129
 
83
- ## Running tests
130
+ ## Running package locally
131
+
132
+ ### Building the package
84
133
 
85
134
  ```bash
86
- pnpm --filter @solana/web3-compat test
135
+ # Build TypeScript definitions
136
+ pnpm --filter @solana/web3-compat build
137
+
138
+ # Or build components separately
139
+ pnpm --filter @solana/web3-compat compile:js
140
+ pnpm --filter @solana/web3-compat compile:typedefs
87
141
  ```
88
142
 
89
- ## Examples
143
+ ### Running tests
90
144
 
91
- We've included some examples that are directly taken from Solana project code (eg `explorer`). We'll keep
92
- updating these throughout the phases.
145
+ ```bash
146
+ # Run all tests
147
+ pnpm --filter @solana/web3-compat test
148
+ ```
93
149
 
94
150
  ## Known limitations & edge cases
95
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3-compat",
3
- "version": "0.0.5",
3
+ "version": "0.0.6-rc.1",
4
4
  "description": "Compatibility layer that preserves the web3.js API while delegating to Kit primitives under the hood",
5
5
  "exports": {
6
6
  "edge-light": {
@@ -53,7 +53,7 @@
53
53
  "@solana/transactions": "^5.0.0",
54
54
  "@solana/web3.js": "^1.95.3",
55
55
  "bs58": "^6.0.0",
56
- "@solana/client": "0.2.2"
56
+ "@solana/client": "1.0.0-rc.1"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "^24"