@solana/kit 6.3.1 → 6.3.2-canary-20260313112147
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/dist/index.development.js +1 -1
- package/dist/index.development.js.map +1 -1
- package/dist/index.production.min.js +1 -1
- package/package.json +27 -26
- package/src/airdrop-internal.ts +38 -0
- package/src/airdrop.ts +80 -0
- package/src/decompile-transaction-message-fetching-lookup-tables.ts +50 -0
- package/src/fetch-lookup-tables.ts +46 -0
- package/src/get-minimum-balance-for-rent-exemption.ts +26 -0
- package/src/index.ts +43 -0
- package/src/program-client-core.ts +1 -0
- package/src/send-and-confirm-durable-nonce-transaction.ts +172 -0
- package/src/send-and-confirm-transaction.ts +95 -0
- package/src/send-transaction-internal.ts +134 -0
- package/src/send-transaction-without-confirming.ts +52 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the JavaScript SDK for building Solana apps for Node, web, and React Native.
|
|
3
|
+
*
|
|
4
|
+
* In addition to re-exporting functions from packages in the `@solana/*` namespace, this package
|
|
5
|
+
* offers additional helpers for building Solana applications, with sensible defaults.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export * from '@solana/accounts';
|
|
10
|
+
export * from '@solana/addresses';
|
|
11
|
+
export * from '@solana/codecs';
|
|
12
|
+
export * from '@solana/errors';
|
|
13
|
+
export * from '@solana/functional';
|
|
14
|
+
export * from '@solana/instructions';
|
|
15
|
+
export * from '@solana/instruction-plans';
|
|
16
|
+
export * from '@solana/keys';
|
|
17
|
+
export * from '@solana/offchain-messages';
|
|
18
|
+
export * from '@solana/plugin-core';
|
|
19
|
+
export type * from '@solana/plugin-interfaces';
|
|
20
|
+
export * from '@solana/programs';
|
|
21
|
+
export * from '@solana/rpc';
|
|
22
|
+
export * from '@solana/rpc-parsed-types';
|
|
23
|
+
export * from '@solana/rpc-subscriptions';
|
|
24
|
+
export * from '@solana/rpc-types';
|
|
25
|
+
export * from '@solana/signers';
|
|
26
|
+
export * from '@solana/transaction-messages';
|
|
27
|
+
export * from '@solana/transactions';
|
|
28
|
+
export * from './airdrop';
|
|
29
|
+
export * from './decompile-transaction-message-fetching-lookup-tables';
|
|
30
|
+
export * from './fetch-lookup-tables';
|
|
31
|
+
export * from './get-minimum-balance-for-rent-exemption';
|
|
32
|
+
export * from './send-and-confirm-durable-nonce-transaction';
|
|
33
|
+
export * from './send-and-confirm-transaction';
|
|
34
|
+
export * from './send-transaction-without-confirming';
|
|
35
|
+
|
|
36
|
+
export type {
|
|
37
|
+
RpcRequest,
|
|
38
|
+
RpcRequestTransformer,
|
|
39
|
+
RpcResponse,
|
|
40
|
+
RpcResponseData,
|
|
41
|
+
RpcResponseTransformer,
|
|
42
|
+
} from '@solana/rpc-spec-types';
|
|
43
|
+
export { createRpcMessage } from '@solana/rpc-spec-types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@solana/program-client-core';
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { getSolanaErrorFromTransactionError, isSolanaError, SOLANA_ERROR__INVALID_NONCE } from '@solana/errors';
|
|
2
|
+
import { Signature } from '@solana/keys';
|
|
3
|
+
import type { GetAccountInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc';
|
|
4
|
+
import type { AccountNotificationsApi, RpcSubscriptions, SignatureNotificationsApi } from '@solana/rpc-subscriptions';
|
|
5
|
+
import { commitmentComparator } from '@solana/rpc-types';
|
|
6
|
+
import {
|
|
7
|
+
createNonceInvalidationPromiseFactory,
|
|
8
|
+
createRecentSignatureConfirmationPromiseFactory,
|
|
9
|
+
waitForDurableNonceTransactionConfirmation,
|
|
10
|
+
} from '@solana/transaction-confirmation';
|
|
11
|
+
import {
|
|
12
|
+
getSignatureFromTransaction,
|
|
13
|
+
SendableTransaction,
|
|
14
|
+
Transaction,
|
|
15
|
+
TransactionWithDurableNonceLifetime,
|
|
16
|
+
} from '@solana/transactions';
|
|
17
|
+
|
|
18
|
+
import { sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';
|
|
19
|
+
|
|
20
|
+
type SendAndConfirmDurableNonceTransactionFunction = (
|
|
21
|
+
transaction: SendableTransaction & Transaction & TransactionWithDurableNonceLifetime,
|
|
22
|
+
config: Omit<
|
|
23
|
+
Parameters<typeof sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT>[0],
|
|
24
|
+
'confirmDurableNonceTransaction' | 'rpc' | 'transaction'
|
|
25
|
+
>,
|
|
26
|
+
) => Promise<void>;
|
|
27
|
+
|
|
28
|
+
type SendAndConfirmDurableNonceTransactionFactoryConfig<TCluster> = {
|
|
29
|
+
/** An object that supports the {@link GetSignatureStatusesApi} and the {@link SendTransactionApi} of the Solana RPC API */
|
|
30
|
+
rpc: Rpc<GetAccountInfoApi & GetSignatureStatusesApi & SendTransactionApi> & { '~cluster'?: TCluster };
|
|
31
|
+
/** An object that supports the {@link AccountNotificationsApi} and the {@link SignatureNotificationsApi} of the Solana RPC Subscriptions API */
|
|
32
|
+
rpcSubscriptions: RpcSubscriptions<AccountNotificationsApi & SignatureNotificationsApi> & { '~cluster'?: TCluster };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns a function that you can call to send a nonce-based transaction to the network and to wait
|
|
37
|
+
* until it has been confirmed.
|
|
38
|
+
*
|
|
39
|
+
* @param config
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import {
|
|
44
|
+
* isSolanaError,
|
|
45
|
+
* sendAndConfirmDurableNonceTransactionFactory,
|
|
46
|
+
* SOLANA_ERROR__INVALID_NONCE,
|
|
47
|
+
* SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND,
|
|
48
|
+
* } from '@solana/kit';
|
|
49
|
+
*
|
|
50
|
+
* const sendAndConfirmNonceTransaction = sendAndConfirmDurableNonceTransactionFactory({ rpc, rpcSubscriptions });
|
|
51
|
+
*
|
|
52
|
+
* try {
|
|
53
|
+
* await sendAndConfirmNonceTransaction(transaction, { commitment: 'confirmed' });
|
|
54
|
+
* } catch (e) {
|
|
55
|
+
* if (isSolanaError(e, SOLANA_ERROR__NONCE_ACCOUNT_NOT_FOUND)) {
|
|
56
|
+
* console.error(
|
|
57
|
+
* 'The lifetime specified by this transaction refers to a nonce account ' +
|
|
58
|
+
* `\`${e.context.nonceAccountAddress}\` that does not exist`,
|
|
59
|
+
* );
|
|
60
|
+
* } else if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) {
|
|
61
|
+
* console.error('This transaction depends on a nonce that is no longer valid');
|
|
62
|
+
* } else {
|
|
63
|
+
* throw e;
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function sendAndConfirmDurableNonceTransactionFactory({
|
|
69
|
+
rpc,
|
|
70
|
+
rpcSubscriptions,
|
|
71
|
+
}: SendAndConfirmDurableNonceTransactionFactoryConfig<'devnet'>): SendAndConfirmDurableNonceTransactionFunction;
|
|
72
|
+
export function sendAndConfirmDurableNonceTransactionFactory({
|
|
73
|
+
rpc,
|
|
74
|
+
rpcSubscriptions,
|
|
75
|
+
}: SendAndConfirmDurableNonceTransactionFactoryConfig<'testnet'>): SendAndConfirmDurableNonceTransactionFunction;
|
|
76
|
+
export function sendAndConfirmDurableNonceTransactionFactory({
|
|
77
|
+
rpc,
|
|
78
|
+
rpcSubscriptions,
|
|
79
|
+
}: SendAndConfirmDurableNonceTransactionFactoryConfig<'mainnet'>): SendAndConfirmDurableNonceTransactionFunction;
|
|
80
|
+
export function sendAndConfirmDurableNonceTransactionFactory<
|
|
81
|
+
TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void,
|
|
82
|
+
>({
|
|
83
|
+
rpc,
|
|
84
|
+
rpcSubscriptions,
|
|
85
|
+
}: SendAndConfirmDurableNonceTransactionFactoryConfig<TCluster>): SendAndConfirmDurableNonceTransactionFunction {
|
|
86
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory({ rpc, rpcSubscriptions } as Parameters<
|
|
87
|
+
typeof createNonceInvalidationPromiseFactory
|
|
88
|
+
>[0]);
|
|
89
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({
|
|
90
|
+
rpc,
|
|
91
|
+
rpcSubscriptions,
|
|
92
|
+
} as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Creates a wrapped version of getNonceInvalidationPromise that handles the race condition
|
|
96
|
+
* where the nonce account update notification arrives before the signature confirmation.
|
|
97
|
+
*
|
|
98
|
+
* When the nonce changes, we check if our transaction actually landed on-chain.
|
|
99
|
+
* If it did, we don't throw - letting the signature confirmation promise continue.
|
|
100
|
+
*/
|
|
101
|
+
function createNonceInvalidationPromiseHandlingRaceCondition(
|
|
102
|
+
signature: Signature,
|
|
103
|
+
): typeof getNonceInvalidationPromise {
|
|
104
|
+
return async function wrappedGetNonceInvalidationPromise(config) {
|
|
105
|
+
try {
|
|
106
|
+
return await getNonceInvalidationPromise(config);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
// If nonce became invalid, check if our transaction actually landed
|
|
109
|
+
if (isSolanaError(e, SOLANA_ERROR__INVALID_NONCE)) {
|
|
110
|
+
let status;
|
|
111
|
+
try {
|
|
112
|
+
const { value: statuses } = await rpc
|
|
113
|
+
.getSignatureStatuses([signature])
|
|
114
|
+
.send({ abortSignal: config.abortSignal });
|
|
115
|
+
status = statuses[0];
|
|
116
|
+
} catch {
|
|
117
|
+
// RPC failed - propagate the original nonce error
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (status === null || status === undefined) {
|
|
122
|
+
// Transaction doesn't exist - nonce was truly invalid
|
|
123
|
+
throw e;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Check if status meets required commitment
|
|
127
|
+
if (
|
|
128
|
+
status.confirmationStatus !== null &&
|
|
129
|
+
commitmentComparator(status.confirmationStatus, config.commitment) >= 0
|
|
130
|
+
) {
|
|
131
|
+
// Transaction failed on-chain, throw the error from the transaction
|
|
132
|
+
if (status.err !== null) {
|
|
133
|
+
throw getSolanaErrorFromTransactionError(status.err);
|
|
134
|
+
}
|
|
135
|
+
// Transaction succeeded, resolve the promise successfully
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Commitment not met yet - return a never-resolving promise
|
|
140
|
+
// This lets the signature confirmation promise continue
|
|
141
|
+
return await new Promise(() => {});
|
|
142
|
+
}
|
|
143
|
+
throw e;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function confirmDurableNonceTransaction(
|
|
149
|
+
config: Omit<
|
|
150
|
+
Parameters<typeof waitForDurableNonceTransactionConfirmation>[0],
|
|
151
|
+
'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'
|
|
152
|
+
>,
|
|
153
|
+
) {
|
|
154
|
+
const wrappedGetNonceInvalidationPromise = createNonceInvalidationPromiseHandlingRaceCondition(
|
|
155
|
+
getSignatureFromTransaction(config.transaction),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
159
|
+
...config,
|
|
160
|
+
getNonceInvalidationPromise: wrappedGetNonceInvalidationPromise,
|
|
161
|
+
getRecentSignatureConfirmationPromise,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return async function sendAndConfirmDurableNonceTransaction(transaction, config) {
|
|
165
|
+
await sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
166
|
+
...config,
|
|
167
|
+
confirmDurableNonceTransaction,
|
|
168
|
+
rpc,
|
|
169
|
+
transaction,
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { GetEpochInfoApi, GetSignatureStatusesApi, Rpc, SendTransactionApi } from '@solana/rpc';
|
|
2
|
+
import type { RpcSubscriptions, SignatureNotificationsApi, SlotNotificationsApi } from '@solana/rpc-subscriptions';
|
|
3
|
+
import {
|
|
4
|
+
createBlockHeightExceedencePromiseFactory,
|
|
5
|
+
createRecentSignatureConfirmationPromiseFactory,
|
|
6
|
+
TransactionWithLastValidBlockHeight,
|
|
7
|
+
waitForRecentTransactionConfirmation,
|
|
8
|
+
} from '@solana/transaction-confirmation';
|
|
9
|
+
import { SendableTransaction, Transaction } from '@solana/transactions';
|
|
10
|
+
|
|
11
|
+
import { sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';
|
|
12
|
+
|
|
13
|
+
type SendAndConfirmTransactionWithBlockhashLifetimeFunction = (
|
|
14
|
+
transaction: SendableTransaction & Transaction & TransactionWithLastValidBlockHeight,
|
|
15
|
+
config: Omit<
|
|
16
|
+
Parameters<typeof sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT>[0],
|
|
17
|
+
'confirmRecentTransaction' | 'rpc' | 'transaction'
|
|
18
|
+
>,
|
|
19
|
+
) => Promise<void>;
|
|
20
|
+
|
|
21
|
+
type SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<TCluster> = {
|
|
22
|
+
/** An object that supports the {@link GetSignatureStatusesApi} and the {@link SendTransactionApi} of the Solana RPC API */
|
|
23
|
+
rpc: Rpc<GetEpochInfoApi & GetSignatureStatusesApi & SendTransactionApi> & { '~cluster'?: TCluster };
|
|
24
|
+
/** An object that supports the {@link SignatureNotificationsApi} and the {@link SlotNotificationsApi} of the Solana RPC Subscriptions API */
|
|
25
|
+
rpcSubscriptions: RpcSubscriptions<SignatureNotificationsApi & SlotNotificationsApi> & { '~cluster'?: TCluster };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns a function that you can call to send a blockhash-based transaction to the network and to
|
|
30
|
+
* wait until it has been confirmed.
|
|
31
|
+
*
|
|
32
|
+
* @param config
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { isSolanaError, sendAndConfirmTransactionFactory, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED } from '@solana/kit';
|
|
37
|
+
*
|
|
38
|
+
* const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
|
|
39
|
+
*
|
|
40
|
+
* try {
|
|
41
|
+
* await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });
|
|
42
|
+
* } catch (e) {
|
|
43
|
+
* if (isSolanaError(e, SOLANA_ERROR__BLOCK_HEIGHT_EXCEEDED)) {
|
|
44
|
+
* console.error('This transaction depends on a blockhash that has expired');
|
|
45
|
+
* } else {
|
|
46
|
+
* throw e;
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function sendAndConfirmTransactionFactory({
|
|
52
|
+
rpc,
|
|
53
|
+
rpcSubscriptions,
|
|
54
|
+
}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'devnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;
|
|
55
|
+
export function sendAndConfirmTransactionFactory({
|
|
56
|
+
rpc,
|
|
57
|
+
rpcSubscriptions,
|
|
58
|
+
}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'testnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;
|
|
59
|
+
export function sendAndConfirmTransactionFactory({
|
|
60
|
+
rpc,
|
|
61
|
+
rpcSubscriptions,
|
|
62
|
+
}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<'mainnet'>): SendAndConfirmTransactionWithBlockhashLifetimeFunction;
|
|
63
|
+
export function sendAndConfirmTransactionFactory<TCluster extends 'devnet' | 'mainnet' | 'testnet' | void = void>({
|
|
64
|
+
rpc,
|
|
65
|
+
rpcSubscriptions,
|
|
66
|
+
}: SendAndConfirmTransactionWithBlockhashLifetimeFactoryConfig<TCluster>): SendAndConfirmTransactionWithBlockhashLifetimeFunction {
|
|
67
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory({
|
|
68
|
+
rpc,
|
|
69
|
+
rpcSubscriptions,
|
|
70
|
+
} as Parameters<typeof createBlockHeightExceedencePromiseFactory>[0]);
|
|
71
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory({
|
|
72
|
+
rpc,
|
|
73
|
+
rpcSubscriptions,
|
|
74
|
+
} as Parameters<typeof createRecentSignatureConfirmationPromiseFactory>[0]);
|
|
75
|
+
async function confirmRecentTransaction(
|
|
76
|
+
config: Omit<
|
|
77
|
+
Parameters<typeof waitForRecentTransactionConfirmation>[0],
|
|
78
|
+
'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise'
|
|
79
|
+
>,
|
|
80
|
+
) {
|
|
81
|
+
await waitForRecentTransactionConfirmation({
|
|
82
|
+
...config,
|
|
83
|
+
getBlockHeightExceedencePromise,
|
|
84
|
+
getRecentSignatureConfirmationPromise,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return async function sendAndConfirmTransaction(transaction, config) {
|
|
88
|
+
await sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
89
|
+
...config,
|
|
90
|
+
confirmRecentTransaction,
|
|
91
|
+
rpc,
|
|
92
|
+
transaction,
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Signature } from '@solana/keys';
|
|
2
|
+
import type { Rpc, SendTransactionApi } from '@solana/rpc';
|
|
3
|
+
import { Commitment, commitmentComparator } from '@solana/rpc-types';
|
|
4
|
+
import {
|
|
5
|
+
TransactionWithLastValidBlockHeight,
|
|
6
|
+
waitForDurableNonceTransactionConfirmation,
|
|
7
|
+
waitForRecentTransactionConfirmation,
|
|
8
|
+
} from '@solana/transaction-confirmation';
|
|
9
|
+
import {
|
|
10
|
+
getBase64EncodedWireTransaction,
|
|
11
|
+
SendableTransaction,
|
|
12
|
+
Transaction,
|
|
13
|
+
TransactionWithDurableNonceLifetime,
|
|
14
|
+
} from '@solana/transactions';
|
|
15
|
+
|
|
16
|
+
interface SendAndConfirmDurableNonceTransactionConfig
|
|
17
|
+
extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {
|
|
18
|
+
confirmDurableNonceTransaction: (
|
|
19
|
+
config: Omit<
|
|
20
|
+
Parameters<typeof waitForDurableNonceTransactionConfirmation>[0],
|
|
21
|
+
'getNonceInvalidationPromise' | 'getRecentSignatureConfirmationPromise'
|
|
22
|
+
>,
|
|
23
|
+
) => Promise<void>;
|
|
24
|
+
transaction: SendableTransaction & Transaction & TransactionWithDurableNonceLifetime;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface SendAndConfirmTransactionWithBlockhashLifetimeConfig
|
|
28
|
+
extends SendTransactionBaseConfig, SendTransactionConfigWithoutEncoding {
|
|
29
|
+
confirmRecentTransaction: (
|
|
30
|
+
config: Omit<
|
|
31
|
+
Parameters<typeof waitForRecentTransactionConfirmation>[0],
|
|
32
|
+
'getBlockHeightExceedencePromise' | 'getRecentSignatureConfirmationPromise'
|
|
33
|
+
>,
|
|
34
|
+
) => Promise<void>;
|
|
35
|
+
transaction: SendableTransaction & Transaction & TransactionWithLastValidBlockHeight;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SendTransactionBaseConfig extends SendTransactionConfigWithoutEncoding {
|
|
39
|
+
abortSignal?: AbortSignal;
|
|
40
|
+
commitment: Commitment;
|
|
41
|
+
rpc: Rpc<SendTransactionApi>;
|
|
42
|
+
transaction: SendableTransaction & Transaction;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type SendTransactionConfigWithoutEncoding = Omit<
|
|
46
|
+
NonNullable<Parameters<SendTransactionApi['sendTransaction']>[1]>,
|
|
47
|
+
'encoding'
|
|
48
|
+
>;
|
|
49
|
+
|
|
50
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(
|
|
51
|
+
commitment: Commitment,
|
|
52
|
+
config?: SendTransactionConfigWithoutEncoding,
|
|
53
|
+
): SendTransactionConfigWithoutEncoding | void {
|
|
54
|
+
if (
|
|
55
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
56
|
+
!config?.preflightCommitment &&
|
|
57
|
+
// The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
58
|
+
commitmentComparator(commitment, 'finalized' /* default value of `preflightCommitment` */) < 0
|
|
59
|
+
) {
|
|
60
|
+
return {
|
|
61
|
+
...config,
|
|
62
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
63
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
64
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
65
|
+
// confirmation commitment.
|
|
66
|
+
preflightCommitment: commitment,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// The commitment at which the developer wishes to confirm the transaction is at least as
|
|
70
|
+
// high as the commitment at which they want to simulate it. Honour the config as-is.
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
75
|
+
abortSignal,
|
|
76
|
+
commitment,
|
|
77
|
+
rpc,
|
|
78
|
+
transaction,
|
|
79
|
+
...sendTransactionConfig
|
|
80
|
+
}: SendTransactionBaseConfig): Promise<Signature> {
|
|
81
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
82
|
+
return await rpc
|
|
83
|
+
.sendTransaction(base64EncodedWireTransaction, {
|
|
84
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
85
|
+
encoding: 'base64',
|
|
86
|
+
})
|
|
87
|
+
.send({ abortSignal });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function sendAndConfirmDurableNonceTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
91
|
+
abortSignal,
|
|
92
|
+
commitment,
|
|
93
|
+
confirmDurableNonceTransaction,
|
|
94
|
+
rpc,
|
|
95
|
+
transaction,
|
|
96
|
+
...sendTransactionConfig
|
|
97
|
+
}: SendAndConfirmDurableNonceTransactionConfig): Promise<Signature> {
|
|
98
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
99
|
+
...sendTransactionConfig,
|
|
100
|
+
abortSignal,
|
|
101
|
+
commitment,
|
|
102
|
+
rpc,
|
|
103
|
+
transaction,
|
|
104
|
+
});
|
|
105
|
+
await confirmDurableNonceTransaction({
|
|
106
|
+
abortSignal,
|
|
107
|
+
commitment,
|
|
108
|
+
transaction,
|
|
109
|
+
});
|
|
110
|
+
return transactionSignature;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function sendAndConfirmTransactionWithBlockhashLifetime_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
114
|
+
abortSignal,
|
|
115
|
+
commitment,
|
|
116
|
+
confirmRecentTransaction,
|
|
117
|
+
rpc,
|
|
118
|
+
transaction,
|
|
119
|
+
...sendTransactionConfig
|
|
120
|
+
}: SendAndConfirmTransactionWithBlockhashLifetimeConfig): Promise<Signature> {
|
|
121
|
+
const transactionSignature = await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
122
|
+
...sendTransactionConfig,
|
|
123
|
+
abortSignal,
|
|
124
|
+
commitment,
|
|
125
|
+
rpc,
|
|
126
|
+
transaction,
|
|
127
|
+
});
|
|
128
|
+
await confirmRecentTransaction({
|
|
129
|
+
abortSignal,
|
|
130
|
+
commitment,
|
|
131
|
+
transaction,
|
|
132
|
+
});
|
|
133
|
+
return transactionSignature;
|
|
134
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Rpc, SendTransactionApi } from '@solana/rpc';
|
|
2
|
+
import { SendableTransaction, Transaction } from '@solana/transactions';
|
|
3
|
+
|
|
4
|
+
import { sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT } from './send-transaction-internal';
|
|
5
|
+
|
|
6
|
+
type SendTransactionWithoutConfirmingFunction = (
|
|
7
|
+
transaction: SendableTransaction & Transaction,
|
|
8
|
+
config: Omit<Parameters<typeof sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT>[0], 'rpc' | 'transaction'>,
|
|
9
|
+
) => Promise<void>;
|
|
10
|
+
|
|
11
|
+
interface SendTransactionWithoutConfirmingFactoryConfig {
|
|
12
|
+
/** An object that supports the {@link SendTransactionApi} of the Solana RPC API */
|
|
13
|
+
rpc: Rpc<SendTransactionApi>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns a function that you can call to send a transaction with any kind of lifetime to the
|
|
18
|
+
* network without waiting for it to be confirmed.
|
|
19
|
+
*
|
|
20
|
+
* @param config
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import {
|
|
25
|
+
* sendTransactionWithoutConfirmingFactory,
|
|
26
|
+
* SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE,
|
|
27
|
+
* } from '@solana/kit';
|
|
28
|
+
*
|
|
29
|
+
* const sendTransaction = sendTransactionWithoutConfirmingFactory({ rpc });
|
|
30
|
+
*
|
|
31
|
+
* try {
|
|
32
|
+
* await sendTransaction(transaction, { commitment: 'confirmed' });
|
|
33
|
+
* } catch (e) {
|
|
34
|
+
* if (isSolanaError(e, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE)) {
|
|
35
|
+
* console.error('The transaction failed in simulation', e.cause);
|
|
36
|
+
* } else {
|
|
37
|
+
* throw e;
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function sendTransactionWithoutConfirmingFactory({
|
|
43
|
+
rpc,
|
|
44
|
+
}: SendTransactionWithoutConfirmingFactoryConfig): SendTransactionWithoutConfirmingFunction {
|
|
45
|
+
return async function sendTransactionWithoutConfirming(transaction, config) {
|
|
46
|
+
await sendTransaction_INTERNAL_ONLY_DO_NOT_EXPORT({
|
|
47
|
+
...config,
|
|
48
|
+
rpc,
|
|
49
|
+
transaction,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|