@solana/web3.js 1.95.2 → 2.0.0-20241006045741
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.
- package/README.md +128 -113
- package/dist/index.browser.cjs +433 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +343 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.development.js +8071 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.mjs +343 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/index.node.cjs +433 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +343 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/index.production.min.js +584 -0
- package/dist/types/airdrop-internal.d.ts +16 -0
- package/dist/types/airdrop-internal.d.ts.map +1 -0
- package/dist/types/airdrop.d.ts +18 -0
- package/dist/types/airdrop.d.ts.map +1 -0
- package/dist/types/compute-limit-internal.d.ts +70 -0
- package/dist/types/compute-limit-internal.d.ts.map +1 -0
- package/dist/types/compute-limit.d.ts +10 -0
- package/dist/types/compute-limit.d.ts.map +1 -0
- package/dist/types/decode-transaction-message.d.ts +9 -0
- package/dist/types/decode-transaction-message.d.ts.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/send-and-confirm-durable-nonce-transaction.d.ts +18 -0
- package/dist/types/send-and-confirm-durable-nonce-transaction.d.ts.map +1 -0
- package/dist/types/send-and-confirm-transaction.d.ts +18 -0
- package/dist/types/send-and-confirm-transaction.d.ts.map +1 -0
- package/dist/types/send-transaction-internal.d.ts +26 -0
- package/dist/types/send-transaction-internal.d.ts.map +1 -0
- package/dist/types/send-transaction-without-confirming.d.ts +10 -0
- package/dist/types/send-transaction-without-confirming.d.ts.map +1 -0
- package/package.json +88 -57
- package/lib/index.browser.cjs.js +0 -10559
- package/lib/index.browser.cjs.js.map +0 -1
- package/lib/index.browser.esm.js +0 -10458
- package/lib/index.browser.esm.js.map +0 -1
- package/lib/index.cjs.js +0 -11256
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts +0 -4021
- package/lib/index.esm.js +0 -11151
- package/lib/index.esm.js.map +0 -1
- package/lib/index.iife.js +0 -25175
- package/lib/index.iife.js.map +0 -1
- package/lib/index.iife.min.js +0 -19
- package/lib/index.iife.min.js.map +0 -1
- package/lib/index.native.js +0 -10559
- package/lib/index.native.js.map +0 -1
- package/src/__forks__/browser/fetch-impl.ts +0 -4
- package/src/__forks__/react-native/fetch-impl.ts +0 -4
- package/src/account-data.ts +0 -39
- package/src/account.ts +0 -55
- package/src/blockhash.ts +0 -4
- package/src/bpf-loader-deprecated.ts +0 -5
- package/src/bpf-loader.ts +0 -50
- package/src/connection.ts +0 -6951
- package/src/epoch-schedule.ts +0 -102
- package/src/errors.ts +0 -133
- package/src/fee-calculator.ts +0 -18
- package/src/fetch-impl.ts +0 -16
- package/src/index.ts +0 -24
- package/src/instruction.ts +0 -58
- package/src/keypair.ts +0 -102
- package/src/layout.ts +0 -188
- package/src/loader.ts +0 -267
- package/src/message/account-keys.ts +0 -79
- package/src/message/compiled-keys.ts +0 -165
- package/src/message/index.ts +0 -47
- package/src/message/legacy.ts +0 -323
- package/src/message/v0.ts +0 -513
- package/src/message/versioned.ts +0 -36
- package/src/nonce-account.ts +0 -82
- package/src/programs/address-lookup-table/index.ts +0 -435
- package/src/programs/address-lookup-table/state.ts +0 -84
- package/src/programs/compute-budget.ts +0 -281
- package/src/programs/ed25519.ts +0 -157
- package/src/programs/index.ts +0 -7
- package/src/programs/secp256k1.ts +0 -228
- package/src/programs/stake.ts +0 -952
- package/src/programs/system.ts +0 -1048
- package/src/programs/vote.ts +0 -586
- package/src/publickey.ts +0 -259
- package/src/rpc-websocket.ts +0 -75
- package/src/sysvar.ts +0 -37
- package/src/timing.ts +0 -23
- package/src/transaction/constants.ts +0 -12
- package/src/transaction/expiry-custom-errors.ts +0 -48
- package/src/transaction/index.ts +0 -5
- package/src/transaction/legacy.ts +0 -970
- package/src/transaction/message.ts +0 -140
- package/src/transaction/versioned.ts +0 -127
- package/src/utils/assert.ts +0 -8
- package/src/utils/bigint.ts +0 -43
- package/src/utils/borsh-schema.ts +0 -38
- package/src/utils/cluster.ts +0 -35
- package/src/utils/ed25519.ts +0 -43
- package/src/utils/guarded-array-utils.ts +0 -34
- package/src/utils/index.ts +0 -5
- package/src/utils/makeWebsocketUrl.ts +0 -26
- package/src/utils/promise-timeout.ts +0 -14
- package/src/utils/secp256k1.ts +0 -11
- package/src/utils/send-and-confirm-raw-transaction.ts +0 -110
- package/src/utils/send-and-confirm-transaction.ts +0 -106
- package/src/utils/shortvec-encoding.ts +0 -28
- package/src/utils/sleep.ts +0 -4
- package/src/utils/to-buffer.ts +0 -11
- package/src/validator-info.ts +0 -108
- package/src/vote-account.ts +0 -236
package/README.md
CHANGED
|
@@ -6,150 +6,165 @@
|
|
|
6
6
|
|
|
7
7
|
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
8
8
|
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
9
|
-
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js.svg?style=flat
|
|
10
|
-
[npm-image]: https://img.shields.io/npm/v/@solana/web3.js.svg?style=flat
|
|
11
|
-
[npm-url]: https://www.npmjs.com/package/@solana/web3.js
|
|
9
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js/rc.svg?style=flat
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/web3.js/rc.svg?style=flat
|
|
11
|
+
[npm-url]: https://www.npmjs.com/package/@solana/web3.js/v/rc
|
|
12
12
|
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
13
13
|
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
14
14
|
|
|
15
|
-
#
|
|
15
|
+
# @solana/web3.js
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
This is the JavaScript SDK for building Solana apps for Node, web, and React Native.
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Functions
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
In addition to reexporting functions from packages in the `@solana/*` namespace, this package offers additional helpers for building Solana applications, with sensible defaults.
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
### `airdropFactory({rpc, rpcSubscriptions})`
|
|
24
|
+
|
|
25
|
+
Returns a function that you can call to airdrop a certain amount of `Lamports` to a Solana address.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
```ts
|
|
28
|
+
import {
|
|
29
|
+
address,
|
|
30
|
+
airdropFactory,
|
|
31
|
+
createSolanaRpc,
|
|
32
|
+
createSolanaRpcSubscriptions,
|
|
33
|
+
devnet,
|
|
34
|
+
lamports,
|
|
35
|
+
} from '@solana/web3.js';
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
|
|
37
|
+
const rpc = createSolanaRpc(devnet('http://127.0.0.1:8899'));
|
|
38
|
+
const rpcSubscriptions = createSolanaRpcSubscriptions(devnet('ws://127.0.0.1:8900'));
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
const airdrop = airdropFactory({ rpc, rpcSubscriptions });
|
|
41
|
+
|
|
42
|
+
await airdrop({
|
|
43
|
+
commitment: 'confirmed',
|
|
44
|
+
recipientAddress: address('FnHyam9w4NZoWR6mKN1CuGBritdsEWZQa4Z4oawLZGxa'),
|
|
45
|
+
lamports: lamports(10_000_000n),
|
|
46
|
+
});
|
|
35
47
|
```
|
|
36
48
|
|
|
37
|
-
|
|
49
|
+
> [!NOTE] This only works on test clusters.
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
- For more detail on individual functions, see the [latest API Documentation](https://solana-labs.github.io/solana-web3.js)
|
|
51
|
+
### `decodeTransactionMessage(compiledTransactionMessage, rpc, config)`
|
|
41
52
|
|
|
42
|
-
|
|
53
|
+
Returns a `TransactionMessage` from a `CompiledTransactionMessage`. If any of the accounts in the compiled message require an address lookup table to find their address, this function will use the supplied RPC instance to fetch the contents of the address lookup table from the network.
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
### `fetchLookupTables(lookupTableAddresses, rpc, config)`
|
|
45
56
|
|
|
46
|
-
|
|
57
|
+
Given a list of addresses belonging to address lookup tables, returns a map of lookup table addresses to an ordered array of the addresses they contain.
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
- Source code, if possible
|
|
50
|
-
- The text of any errors you encountered, with stacktraces if available
|
|
59
|
+
### `getComputeUnitEstimateForTransactionMessageFactory({rpc})`
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
Correctly budgeting a compute unit limit for your transaction message can increase the probability that your transaction will be accepted for processing. If you don't declare a compute unit limit on your transaction, validators will assume an upper limit of 200K compute units (CU) per instruction.
|
|
53
62
|
|
|
54
|
-
|
|
63
|
+
Since validators have an incentive to pack as many transactions into each block as possible, they may choose to include transactions that they know will fit into the remaining compute budget for the current block over transactions that might not. For this reason, you should set a compute unit limit on each of your transaction messages, whenever possible.
|
|
55
64
|
|
|
56
|
-
|
|
57
|
-
- Chrome: May 2018
|
|
58
|
-
- Firefox: July 2019
|
|
59
|
-
- Safari: September 2020
|
|
60
|
-
- Mobile Safari: September 2020
|
|
61
|
-
- Edge: January 2020
|
|
62
|
-
- Opera: June 2018
|
|
63
|
-
- Samsung Internet: April 2019
|
|
64
|
-
- Runtimes, [by version](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt):
|
|
65
|
-
- Deno: >=1.0
|
|
66
|
-
- Node: >=10.4.0
|
|
67
|
-
- React Native:
|
|
68
|
-
- \>=0.7.0 using the [Hermes](https://reactnative.dev/blog/2022/07/08/hermes-as-the-default) engine ([integration guide](https://solanacookbook.com/integrations/react-native.html#how-to-use-solana-web3-js-in-a-react-native-app)):
|
|
65
|
+
Use this utility to estimate the actual compute unit cost of a given transaction message.
|
|
69
66
|
|
|
70
|
-
|
|
67
|
+
```ts
|
|
68
|
+
import { getSetComputeUnitLimitInstruction } from '@solana-program/compute-budget';
|
|
69
|
+
import { createSolanaRpc, getComputeUnitEstimateForTransactionMessageFactory, pipe } from '@solana/web3.js';
|
|
71
70
|
|
|
72
|
-
|
|
71
|
+
// Create an estimator function.
|
|
72
|
+
const rpc = createSolanaRpc('http://127.0.0.1:8899');
|
|
73
|
+
const getComputeUnitEstimateForTransactionMessage = getComputeUnitEstimateForTransactionMessageFactory({
|
|
74
|
+
rpc,
|
|
75
|
+
});
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
// Create your transaction message.
|
|
78
|
+
const transactionMessage = pipe(
|
|
79
|
+
createTransactionMessage({ version: 'legacy' }),
|
|
80
|
+
/* ... */
|
|
81
|
+
);
|
|
75
82
|
|
|
76
|
-
|
|
83
|
+
// Request an estimate of the actual compute units this message will consume.
|
|
84
|
+
const computeUnitsEstimate = await getComputeUnitEstimateForTransactionMessage(transactionMessage);
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
// Set the transaction message's compute unit budget.
|
|
87
|
+
const transactionMessageWithComputeUnitLimit = prependTransactionMessageInstruction(
|
|
88
|
+
getSetComputeUnitLimitInstruction({ units: computeUnitsEstimate }),
|
|
89
|
+
transactionMessage,
|
|
90
|
+
);
|
|
80
91
|
```
|
|
81
92
|
|
|
82
|
-
|
|
93
|
+
> [!WARNING]
|
|
94
|
+
> The compute unit estimate is just that – an estimate. The compute unit consumption of the actual transaction might be higher or lower than what was observed in simulation. Unless you are confident that your particular transaction message will consume the same or fewer compute units as was estimated, you might like to augment the estimate by either a fixed number of CUs or a multiplier.
|
|
95
|
+
|
|
96
|
+
> [!NOTE]
|
|
97
|
+
> If you are preparing an _unsigned_ transaction, destined to be signed and submitted to the network by a wallet, you might like to leave it up to the wallet to determine the compute unit limit. Consider that the wallet might have a more global view of how many compute units certain types of transactions consume, and might be able to make better estimates of an appropriate compute unit budget.
|
|
98
|
+
|
|
99
|
+
### `sendAndConfirmDurableNonceTransactionFactory({rpc, rpcSubscriptions})`
|
|
100
|
+
|
|
101
|
+
Returns a function that you can call to send a nonce-based transaction to the network and to wait until it has been confirmed.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import {
|
|
105
|
+
isSolanaError,
|
|
106
|
+
sendAndConfirmDurableNonceTransactionFactory,
|
|
107
|
+
SOLANA_ERROR__INVALID_NONCE,
|
|
108
|
+
SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,
|
|
109
|
+
} from '@solana/web3.js';
|
|
110
|
+
|
|
111
|
+
const sendAndConfirmNonceTransaction = sendAndConfirmDurableNonceTransactionFactory({ rpc, rpcSubscriptions });
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
await sendAndConfirmNonceTransaction(transaction, { commitment: 'confirmed' });
|
|
115
|
+
} catch (e) {
|
|
116
|
+
if (isSolanaError(e, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND)) {
|
|
117
|
+
console.error(
|
|
118
|
+
'The lifetime specified by this transaction refers to a nonce account ' +
|
|
119
|
+
`\`${e.context.nonceAccountAddress}\` that does not exist`,
|
|
120
|
+
);
|
|
121
|
+
} else if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) {
|
|
122
|
+
console.error('This transaction depends on a nonce that is no longer valid');
|
|
123
|
+
} else {
|
|
124
|
+
throw e;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
83
128
|
|
|
84
|
-
|
|
129
|
+
### `sendAndConfirmTransactionFactory({rpc, rpcSubscriptions})`
|
|
85
130
|
|
|
86
|
-
|
|
131
|
+
Returns a function that you can call to send a blockhash-based transaction to the network and to wait until it has been confirmed.
|
|
87
132
|
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
```
|
|
133
|
+
```ts
|
|
134
|
+
import { isSolanaError, sendAndConfirmTransactionFactory, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED } from '@solana/web3.js';
|
|
91
135
|
|
|
92
|
-
|
|
136
|
+
const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
|
|
93
137
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
138
|
+
try {
|
|
139
|
+
await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (isSolanaError(e, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {
|
|
142
|
+
console.error('This transaction depends on a blockhash that has expired');
|
|
143
|
+
} else {
|
|
144
|
+
throw e;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
97
147
|
```
|
|
98
148
|
|
|
99
|
-
###
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
the reader to check and validate their accuracy and truthfulness.
|
|
122
|
-
Furthermore nothing in this project constitutes a solicitation for
|
|
123
|
-
investment.
|
|
124
|
-
|
|
125
|
-
Any content produced by SF or developer resources that SF provides, are
|
|
126
|
-
for educational and inspiration purposes only. SF does not encourage,
|
|
127
|
-
induce or sanction the deployment, integration or use of any such
|
|
128
|
-
applications (including the code comprising the Solana blockchain
|
|
129
|
-
protocol) in violation of applicable laws or regulations and hereby
|
|
130
|
-
prohibits any such deployment, integration or use. This includes use of
|
|
131
|
-
any such applications by the reader (a) in violation of export control
|
|
132
|
-
or sanctions laws of the United States or any other applicable
|
|
133
|
-
jurisdiction, (b) if the reader is located in or ordinarily resident in
|
|
134
|
-
a country or territory subject to comprehensive sanctions administered
|
|
135
|
-
by the U.S. Office of Foreign Assets Control (OFAC), or (c) if the
|
|
136
|
-
reader is or is working on behalf of a Specially Designated National
|
|
137
|
-
(SDN) or a person subject to similar blocking or denied party
|
|
138
|
-
prohibitions.
|
|
139
|
-
|
|
140
|
-
The reader should be aware that U.S. export control and sanctions laws
|
|
141
|
-
prohibit U.S. persons (and other persons that are subject to such laws)
|
|
142
|
-
from transacting with persons in certain countries and territories or
|
|
143
|
-
that are on the SDN list. As a project based primarily on open-source
|
|
144
|
-
software, it is possible that such sanctioned persons may nevertheless
|
|
145
|
-
bypass prohibitions, obtain the code comprising the Solana blockchain
|
|
146
|
-
protocol (or other project code or applications) and deploy, integrate,
|
|
147
|
-
or otherwise use it. Accordingly, there is a risk to individuals that
|
|
148
|
-
other persons using the Solana blockchain protocol may be sanctioned
|
|
149
|
-
persons and that transactions with such persons would be a violation of
|
|
150
|
-
U.S. export controls and sanctions law. This risk applies to
|
|
151
|
-
individuals, organizations, and other ecosystem participants that
|
|
152
|
-
deploy, integrate, or use the Solana blockchain protocol code directly
|
|
153
|
-
(e.g., as a node operator), and individuals that transact on the Solana
|
|
154
|
-
blockchain through light clients, third party interfaces, and/or wallet
|
|
155
|
-
software.
|
|
149
|
+
### `sendTransactionWithoutConfirmingFactory({rpc, rpcSubscriptions})`
|
|
150
|
+
|
|
151
|
+
Returns a function that you can call to send a transaction with any kind of lifetime to the network without waiting for it to be confirmed.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import {
|
|
155
|
+
sendTransactionWithoutConfirmingFactory,
|
|
156
|
+
SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE,
|
|
157
|
+
} from '@solana/web3.js';
|
|
158
|
+
|
|
159
|
+
const sendTransaction = sendTransactionWithoutConfirmingFactory({ rpc });
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
await sendTransaction(transaction, { commitment: 'confirmed' });
|
|
163
|
+
} catch (e) {
|
|
164
|
+
if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) {
|
|
165
|
+
console.error('The transaction failed in simulation', e.cause);
|
|
166
|
+
} else {
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|