near-kit 0.0.0 → 0.2.0
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/LICENSE +21 -0
- package/README.md +473 -2
- package/dist/contracts/contract.d.ts +63 -0
- package/dist/contracts/contract.d.ts.map +1 -0
- package/dist/contracts/contract.js +42 -0
- package/dist/contracts/contract.js.map +1 -0
- package/dist/contracts/index.d.ts +5 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +5 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/core/actions.d.ts +193 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +195 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/config-schemas.d.ts +179 -0
- package/dist/core/config-schemas.d.ts.map +1 -0
- package/dist/core/config-schemas.js +169 -0
- package/dist/core/config-schemas.js.map +1 -0
- package/dist/core/constants.d.ts +43 -0
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/constants.js +49 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/near.d.ts +301 -0
- package/dist/core/near.d.ts.map +1 -0
- package/dist/core/near.js +504 -0
- package/dist/core/near.js.map +1 -0
- package/dist/core/nonce-manager.d.ts +39 -0
- package/dist/core/nonce-manager.d.ts.map +1 -0
- package/dist/core/nonce-manager.js +73 -0
- package/dist/core/nonce-manager.js.map +1 -0
- package/dist/core/rpc/rpc-error-handler.d.ts +60 -0
- package/dist/core/rpc/rpc-error-handler.d.ts.map +1 -0
- package/dist/core/rpc/rpc-error-handler.js +324 -0
- package/dist/core/rpc/rpc-error-handler.js.map +1 -0
- package/dist/core/rpc/rpc-schemas.d.ts +1812 -0
- package/dist/core/rpc/rpc-schemas.d.ts.map +1 -0
- package/dist/core/rpc/rpc-schemas.js +424 -0
- package/dist/core/rpc/rpc-schemas.js.map +1 -0
- package/dist/core/rpc/rpc.d.ts +117 -0
- package/dist/core/rpc/rpc.d.ts.map +1 -0
- package/dist/core/rpc/rpc.js +325 -0
- package/dist/core/rpc/rpc.js.map +1 -0
- package/dist/core/schema.d.ts +1188 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +396 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/transaction.d.ts +390 -0
- package/dist/core/transaction.d.ts.map +1 -0
- package/dist/core/transaction.js +653 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/core/types.d.ts +271 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +9 -0
- package/dist/core/types.js.map +1 -0
- package/dist/errors/index.d.ts +226 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +366 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/credential-schemas.d.ts +98 -0
- package/dist/keys/credential-schemas.d.ts.map +1 -0
- package/dist/keys/credential-schemas.js +128 -0
- package/dist/keys/credential-schemas.js.map +1 -0
- package/dist/keys/file-keystore.d.ts +130 -0
- package/dist/keys/file-keystore.d.ts.map +1 -0
- package/dist/keys/file-keystore.js +266 -0
- package/dist/keys/file-keystore.js.map +1 -0
- package/dist/keys/in-memory-keystore.d.ts +71 -0
- package/dist/keys/in-memory-keystore.d.ts.map +1 -0
- package/dist/keys/in-memory-keystore.js +85 -0
- package/dist/keys/in-memory-keystore.js.map +1 -0
- package/dist/keys/index.d.ts +14 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +20 -0
- package/dist/keys/index.js.map +1 -0
- package/dist/keys/native-keystore.d.ts +111 -0
- package/dist/keys/native-keystore.d.ts.map +1 -0
- package/dist/keys/native-keystore.js +167 -0
- package/dist/keys/native-keystore.js.map +1 -0
- package/dist/keys/rotating-keystore.d.ts +207 -0
- package/dist/keys/rotating-keystore.d.ts.map +1 -0
- package/dist/keys/rotating-keystore.js +240 -0
- package/dist/keys/rotating-keystore.js.map +1 -0
- package/dist/sandbox/index.d.ts +6 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/sandbox.d.ts +55 -0
- package/dist/sandbox/sandbox.d.ts.map +1 -0
- package/dist/sandbox/sandbox.js +341 -0
- package/dist/sandbox/sandbox.js.map +1 -0
- package/dist/utils/amount.d.ts +76 -0
- package/dist/utils/amount.d.ts.map +1 -0
- package/dist/utils/amount.js +137 -0
- package/dist/utils/amount.js.map +1 -0
- package/dist/utils/gas.d.ts +69 -0
- package/dist/utils/gas.d.ts.map +1 -0
- package/dist/utils/gas.js +92 -0
- package/dist/utils/gas.js.map +1 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/key.d.ts +117 -0
- package/dist/utils/key.d.ts.map +1 -0
- package/dist/utils/key.js +270 -0
- package/dist/utils/key.js.map +1 -0
- package/dist/utils/nep413.d.ts +97 -0
- package/dist/utils/nep413.d.ts.map +1 -0
- package/dist/utils/nep413.js +154 -0
- package/dist/utils/nep413.js.map +1 -0
- package/dist/utils/validation.d.ts +114 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +150 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/wallets/adapters.d.ts +119 -0
- package/dist/wallets/adapters.d.ts.map +1 -0
- package/dist/wallets/adapters.js +267 -0
- package/dist/wallets/adapters.js.map +1 -0
- package/dist/wallets/index.d.ts +11 -0
- package/dist/wallets/index.d.ts.map +1 -0
- package/dist/wallets/index.js +2 -0
- package/dist/wallets/index.js.map +1 -0
- package/dist/wallets/types.d.ts +99 -0
- package/dist/wallets/types.d.ts.map +1 -0
- package/dist/wallets/types.js +10 -0
- package/dist/wallets/types.js.map +1 -0
- package/package.json +78 -7
- package/index.js +0 -1
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent API for building and sending NEAR transactions.
|
|
3
|
+
*
|
|
4
|
+
* Allows chaining multiple actions (transfers, function calls, account creation, etc.)
|
|
5
|
+
* into a single atomic transaction. All actions either succeed together or fail together.
|
|
6
|
+
*
|
|
7
|
+
* The builder is created via {@link Near.transaction} with a signer account ID. This
|
|
8
|
+
* account must have signing credentials available (via keyStore, privateKey, custom
|
|
9
|
+
* signer, or wallet connection).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Single action
|
|
14
|
+
* await near.transaction('alice.near')
|
|
15
|
+
* .transfer('bob.near', '10 NEAR')
|
|
16
|
+
* .send()
|
|
17
|
+
*
|
|
18
|
+
* // Multiple actions (atomic)
|
|
19
|
+
* await near.transaction('alice.near')
|
|
20
|
+
* .createAccount('sub.alice.near')
|
|
21
|
+
* .transfer('sub.alice.near', '5 NEAR')
|
|
22
|
+
* .addKey(newKey, { type: 'fullAccess' })
|
|
23
|
+
* .send()
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - The `signerId` (set via `Near.transaction()`) is the account that signs and pays for gas
|
|
28
|
+
* - All actions execute in the order they are added
|
|
29
|
+
* - Transaction is only sent when `.send()` is called
|
|
30
|
+
* - Use `.build()` to get unsigned transaction
|
|
31
|
+
*/
|
|
32
|
+
import { type Amount, type Gas, type PrivateKey } from "../utils/validation.js";
|
|
33
|
+
import type { RpcClient } from "./rpc/rpc.js";
|
|
34
|
+
import { type SignedDelegateAction } from "./schema.js";
|
|
35
|
+
import type { FinalExecutionOutcomeMap, KeyStore, PublicKey, SendOptions, Signer, Transaction, TxExecutionStatus, WalletConnection } from "./types.js";
|
|
36
|
+
/**
|
|
37
|
+
* User-friendly access key permission format
|
|
38
|
+
*/
|
|
39
|
+
export type AccessKeyPermission = {
|
|
40
|
+
type: "fullAccess";
|
|
41
|
+
} | {
|
|
42
|
+
type: "functionCall";
|
|
43
|
+
receiverId: string;
|
|
44
|
+
methodNames?: string[];
|
|
45
|
+
allowance?: Amount;
|
|
46
|
+
};
|
|
47
|
+
type DelegateSigningOptions = {
|
|
48
|
+
receiverId?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Explicit block height at which the delegate action expires.
|
|
51
|
+
* If omitted, uses the current block height plus `blockHeightOffset`.
|
|
52
|
+
*/
|
|
53
|
+
maxBlockHeight?: bigint;
|
|
54
|
+
/**
|
|
55
|
+
* Number of blocks after the current height when the delegate action should expire.
|
|
56
|
+
* Defaults to 200 blocks if neither this nor `maxBlockHeight` is provided.
|
|
57
|
+
*/
|
|
58
|
+
blockHeightOffset?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Override nonce to use for the delegate action. If omitted, the builder fetches
|
|
61
|
+
* the access key and uses (nonce + 1).
|
|
62
|
+
*/
|
|
63
|
+
nonce?: bigint;
|
|
64
|
+
/**
|
|
65
|
+
* Explicit public key to embed in the delegate action. Only required when the key
|
|
66
|
+
* cannot be resolved from the configured key store.
|
|
67
|
+
*/
|
|
68
|
+
publicKey?: string | PublicKey;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Fluent builder for constructing and sending NEAR transactions.
|
|
72
|
+
*
|
|
73
|
+
* Created via {@link Near.transaction}. Supports chaining multiple actions
|
|
74
|
+
* (transfers, function calls, key management, staking, delegate actions) into
|
|
75
|
+
* a single atomic transaction.
|
|
76
|
+
*/
|
|
77
|
+
export declare class TransactionBuilder {
|
|
78
|
+
private static nonceManager;
|
|
79
|
+
private signerId;
|
|
80
|
+
private actions;
|
|
81
|
+
private receiverId?;
|
|
82
|
+
private rpc;
|
|
83
|
+
private keyStore;
|
|
84
|
+
private signer?;
|
|
85
|
+
private keyPair?;
|
|
86
|
+
private wallet?;
|
|
87
|
+
private defaultWaitUntil;
|
|
88
|
+
private ensureKeyStoreReady?;
|
|
89
|
+
private cachedSignedTx?;
|
|
90
|
+
constructor(signerId: string, rpc: RpcClient, keyStore: KeyStore, signer?: Signer, defaultWaitUntil?: TxExecutionStatus, wallet?: WalletConnection, ensureKeyStoreReady?: () => Promise<void>);
|
|
91
|
+
/**
|
|
92
|
+
* Invalidate cached signed transaction when builder state changes
|
|
93
|
+
*/
|
|
94
|
+
private invalidateCache;
|
|
95
|
+
/**
|
|
96
|
+
* Resolve the key pair for the current signer from either `signWith()` or keyStore.
|
|
97
|
+
*/
|
|
98
|
+
private resolveKeyPair;
|
|
99
|
+
/**
|
|
100
|
+
* Add a token transfer action.
|
|
101
|
+
*
|
|
102
|
+
* @param receiverId - Account ID that will receive the tokens.
|
|
103
|
+
* @param amount - Amount to transfer, expressed as {@link Amount} (e.g. `"10 NEAR"`).
|
|
104
|
+
*
|
|
105
|
+
* @returns This builder instance for chaining.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* If no receiver has been set yet, this also sets the transaction `receiverId`
|
|
109
|
+
* to `receiverId`.
|
|
110
|
+
*/
|
|
111
|
+
transfer(receiverId: string, amount: Amount): this;
|
|
112
|
+
/**
|
|
113
|
+
* Add a function call action.
|
|
114
|
+
*
|
|
115
|
+
* @param contractId - Account ID of the target contract.
|
|
116
|
+
* @param methodName - Name of the change method to call.
|
|
117
|
+
* @param args - Arguments object or raw bytes; defaults to `{}`.
|
|
118
|
+
* @param options - Optional gas and attached deposit settings.
|
|
119
|
+
*
|
|
120
|
+
* @returns This builder instance for chaining.
|
|
121
|
+
*
|
|
122
|
+
* @remarks
|
|
123
|
+
* - `options.gas` accepts human-readable values such as `"30 Tgas"` or {@link Gas.Tgas}.
|
|
124
|
+
* - `options.attachedDeposit` uses {@link Amount} semantics (e.g. `"1 yocto"`).
|
|
125
|
+
* - If no receiver has been set yet, this also sets the transaction `receiverId`
|
|
126
|
+
* to `contractId`.
|
|
127
|
+
*/
|
|
128
|
+
functionCall(contractId: string, methodName: string, args?: object | Uint8Array, options?: {
|
|
129
|
+
gas?: Gas;
|
|
130
|
+
attachedDeposit?: Amount;
|
|
131
|
+
}): this;
|
|
132
|
+
/**
|
|
133
|
+
* Add a create account action
|
|
134
|
+
*/
|
|
135
|
+
createAccount(accountId: string): this;
|
|
136
|
+
/**
|
|
137
|
+
* Add a delete account action
|
|
138
|
+
*/
|
|
139
|
+
deleteAccount(beneficiaryId: string): this;
|
|
140
|
+
/**
|
|
141
|
+
* Add a deploy contract action
|
|
142
|
+
*/
|
|
143
|
+
deployContract(accountId: string, code: Uint8Array): this;
|
|
144
|
+
/**
|
|
145
|
+
* Publish a global contract that can be reused by multiple accounts
|
|
146
|
+
*
|
|
147
|
+
* @param code - The compiled contract code bytes
|
|
148
|
+
* @param publisherId - Optional account ID. If provided, creates a mutable contract (can be updated).
|
|
149
|
+
* If omitted, creates an immutable contract (identified by code hash).
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // Publish immutable contract (identified by code hash)
|
|
154
|
+
* await near.transaction(accountId)
|
|
155
|
+
* .publishContract(contractCode)
|
|
156
|
+
* .send()
|
|
157
|
+
*
|
|
158
|
+
* // Publish mutable contract (identified by account, can be updated)
|
|
159
|
+
* await near.transaction(accountId)
|
|
160
|
+
* .publishContract(contractCode, "my-publisher.near")
|
|
161
|
+
* .send()
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
publishContract(code: Uint8Array, publisherId?: string): this;
|
|
165
|
+
/**
|
|
166
|
+
* Deploy a contract to this account from previously published code in the global registry
|
|
167
|
+
*
|
|
168
|
+
* @param reference - Reference to the published contract, either:
|
|
169
|
+
* - { codeHash: Uint8Array | string } - Reference by code hash (Uint8Array or base58 string)
|
|
170
|
+
* - { accountId: string } - Reference by the account that published it
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Deploy from code hash (Uint8Array)
|
|
175
|
+
* await near.transaction(accountId)
|
|
176
|
+
* .deployFromPublished({ codeHash: hashBytes })
|
|
177
|
+
* .send()
|
|
178
|
+
*
|
|
179
|
+
* // Deploy from code hash (base58 string)
|
|
180
|
+
* await near.transaction(accountId)
|
|
181
|
+
* .deployFromPublished({ codeHash: "5FzD8..." })
|
|
182
|
+
* .send()
|
|
183
|
+
*
|
|
184
|
+
* // Deploy from account ID
|
|
185
|
+
* await near.transaction(accountId)
|
|
186
|
+
* .deployFromPublished({ accountId: "contract-publisher.near" })
|
|
187
|
+
* .send()
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
deployFromPublished(reference: {
|
|
191
|
+
codeHash: string | Uint8Array;
|
|
192
|
+
} | {
|
|
193
|
+
accountId: string;
|
|
194
|
+
}): this;
|
|
195
|
+
/**
|
|
196
|
+
* Add a stake action
|
|
197
|
+
*/
|
|
198
|
+
stake(publicKey: string, amount: Amount): this;
|
|
199
|
+
/**
|
|
200
|
+
* Add an add key action
|
|
201
|
+
*
|
|
202
|
+
* The key is added to the receiverId of the transaction.
|
|
203
|
+
* If receiverId is not set, it defaults to signerId.
|
|
204
|
+
*/
|
|
205
|
+
addKey(publicKey: string, permission: AccessKeyPermission): this;
|
|
206
|
+
/**
|
|
207
|
+
* Add a delete key action
|
|
208
|
+
*/
|
|
209
|
+
deleteKey(accountId: string, publicKey: string): this;
|
|
210
|
+
/**
|
|
211
|
+
* Build and sign a delegate action from the queued actions.
|
|
212
|
+
*
|
|
213
|
+
* @param options - Optional overrides for receiver, nonce, and expiration
|
|
214
|
+
*/
|
|
215
|
+
/**
|
|
216
|
+
* Add a signed delegate action to this transaction (for relayers).
|
|
217
|
+
*/
|
|
218
|
+
signedDelegateAction(signedDelegate: SignedDelegateAction): this;
|
|
219
|
+
/**
|
|
220
|
+
* Build and sign a delegate action from the queued actions.
|
|
221
|
+
*
|
|
222
|
+
* @returns Signed delegate action ready to be added to a relayer transaction
|
|
223
|
+
*/
|
|
224
|
+
delegate(options?: DelegateSigningOptions): Promise<SignedDelegateAction>;
|
|
225
|
+
/**
|
|
226
|
+
* Override the signing function for this specific transaction.
|
|
227
|
+
*
|
|
228
|
+
* Use this to sign with a different signer than the one configured in the
|
|
229
|
+
* Near client, while keeping the same signerId. Useful for:
|
|
230
|
+
*
|
|
231
|
+
* - Using a hardware wallet for a specific transaction
|
|
232
|
+
* - Testing with mock signers
|
|
233
|
+
* - Signing with a specific private key for the same account
|
|
234
|
+
* - One-off custom signing logic
|
|
235
|
+
*
|
|
236
|
+
* **Important:** This overrides HOW the transaction is signed, not WHO signs it.
|
|
237
|
+
* The signerId (set via `.transaction()`) remains the same. To sign as a different
|
|
238
|
+
* account, use `.transaction(otherAccountId)` instead.
|
|
239
|
+
*
|
|
240
|
+
* @param key - Either a custom signer function or a private key string
|
|
241
|
+
* (e.g., 'ed25519:...' or 'secp256k1:...')
|
|
242
|
+
* Type-safe: TypeScript will enforce the correct format at compile time
|
|
243
|
+
* @returns This builder instance for chaining
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* // Override with different hardware wallet
|
|
248
|
+
* await near.transaction('alice.near')
|
|
249
|
+
* .signWith(aliceHardwareWallet)
|
|
250
|
+
* .transfer('bob.near', '5 NEAR')
|
|
251
|
+
* .send()
|
|
252
|
+
*
|
|
253
|
+
* // Sign with specific ed25519 private key (type-safe)
|
|
254
|
+
* await near.transaction('alice.near')
|
|
255
|
+
* .signWith('ed25519:...') // ✅ TypeScript ensures correct format
|
|
256
|
+
* .transfer('bob.near', '1 NEAR')
|
|
257
|
+
* .send()
|
|
258
|
+
*
|
|
259
|
+
* // Sign with specific secp256k1 private key
|
|
260
|
+
* await near.transaction('alice.near')
|
|
261
|
+
* .signWith('secp256k1:...') // ✅ TypeScript ensures correct format
|
|
262
|
+
* .transfer('bob.near', '1 NEAR')
|
|
263
|
+
* .send()
|
|
264
|
+
*
|
|
265
|
+
* // TypeScript will catch mistakes at compile time:
|
|
266
|
+
* await near.transaction('alice.near')
|
|
267
|
+
* .signWith('alice.near') // ❌ Type error: not a PrivateKey
|
|
268
|
+
*
|
|
269
|
+
* // Mock signer for testing
|
|
270
|
+
* const mockSigner: Signer = async (msg) => ({
|
|
271
|
+
* keyType: KeyType.ED25519,
|
|
272
|
+
* data: new Uint8Array(64)
|
|
273
|
+
* })
|
|
274
|
+
*
|
|
275
|
+
* await near.transaction('test.near')
|
|
276
|
+
* .signWith(mockSigner)
|
|
277
|
+
* .transfer('receiver.near', '1')
|
|
278
|
+
* .send()
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* @remarks
|
|
282
|
+
* Supports both ed25519 and secp256k1 keys.
|
|
283
|
+
*/
|
|
284
|
+
signWith(key: PrivateKey | Signer): this;
|
|
285
|
+
/**
|
|
286
|
+
* Build the unsigned transaction
|
|
287
|
+
*/
|
|
288
|
+
build(): Promise<Transaction>;
|
|
289
|
+
/**
|
|
290
|
+
* Sign the transaction without sending it.
|
|
291
|
+
*
|
|
292
|
+
* This creates a signed transaction that can be:
|
|
293
|
+
* - Inspected via `getHash()`
|
|
294
|
+
* - Serialized via `serialize()`
|
|
295
|
+
* - Sent later via `send()`
|
|
296
|
+
*
|
|
297
|
+
* The signed transaction is cached internally. If you modify the transaction
|
|
298
|
+
* (add actions, change signer, etc.), the cache is automatically invalidated.
|
|
299
|
+
*
|
|
300
|
+
* @returns This builder instance (now in a signed state)
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* // Sign and inspect hash
|
|
305
|
+
* const tx = await near.transaction('alice.near')
|
|
306
|
+
* .transfer('bob.near', '1 NEAR')
|
|
307
|
+
* .sign()
|
|
308
|
+
*
|
|
309
|
+
* console.log('Transaction hash:', tx.getHash())
|
|
310
|
+
*
|
|
311
|
+
* // Serialize for offline use
|
|
312
|
+
* const bytes = tx.serialize()
|
|
313
|
+
*
|
|
314
|
+
* // Send when ready
|
|
315
|
+
* const result = await tx.send({ waitUntil: 'FINAL' })
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
sign(): Promise<this>;
|
|
319
|
+
/**
|
|
320
|
+
* Get the transaction hash (only available after signing).
|
|
321
|
+
*
|
|
322
|
+
* @returns The base58-encoded transaction hash, or null if not yet signed
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const tx = await near.transaction('alice.near')
|
|
327
|
+
* .transfer('bob.near', '1 NEAR')
|
|
328
|
+
* .sign()
|
|
329
|
+
*
|
|
330
|
+
* console.log(tx.getHash()) // "8ZQ7..."
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
getHash(): string | null;
|
|
334
|
+
/**
|
|
335
|
+
* Serialize the signed transaction to bytes.
|
|
336
|
+
*
|
|
337
|
+
* This is useful for:
|
|
338
|
+
* - Storing signed transactions for later broadcast
|
|
339
|
+
* - Sending transactions through external tools
|
|
340
|
+
* - Multi-sig workflows
|
|
341
|
+
*
|
|
342
|
+
* @returns Borsh-serialized signed transaction bytes
|
|
343
|
+
* @throws {NearError} If transaction has not been signed yet
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const tx = await near.transaction('alice.near')
|
|
348
|
+
* .transfer('bob.near', '1 NEAR')
|
|
349
|
+
* .sign()
|
|
350
|
+
*
|
|
351
|
+
* const bytes = tx.serialize()
|
|
352
|
+
* fs.writeFileSync('transaction.bin', bytes)
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
serialize(): Uint8Array;
|
|
356
|
+
/**
|
|
357
|
+
* Sign and send the transaction
|
|
358
|
+
*
|
|
359
|
+
* If the transaction has already been signed (via `.sign()`), it will use the
|
|
360
|
+
* cached signed transaction. Otherwise, it will sign the transaction automatically.
|
|
361
|
+
*
|
|
362
|
+
* The response will always include `transaction.hash` for tracking, even when
|
|
363
|
+
* using `waitUntil: "NONE"` which normally doesn't return transaction details.
|
|
364
|
+
*
|
|
365
|
+
* @param options - Optional configuration for sending the transaction
|
|
366
|
+
* @param options.waitUntil - Controls when the RPC returns after submitting the transaction
|
|
367
|
+
* @returns Promise resolving to the final execution outcome
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* // Use default wait until
|
|
372
|
+
* await near.transaction(account).transfer(receiver, "1 NEAR").send()
|
|
373
|
+
*
|
|
374
|
+
* // Wait for full finality
|
|
375
|
+
* await near.transaction(account)
|
|
376
|
+
* .transfer(receiver, "1 NEAR")
|
|
377
|
+
* .send({ waitUntil: "FINAL" })
|
|
378
|
+
*
|
|
379
|
+
* // Fire and forget with NONE - hash still available
|
|
380
|
+
* const result = await near.transaction(account)
|
|
381
|
+
* .transfer(receiver, "1 NEAR")
|
|
382
|
+
* .send({ waitUntil: "NONE" })
|
|
383
|
+
* console.log(result.transaction.hash) // Always available!
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
send(): Promise<FinalExecutionOutcomeMap["EXECUTED_OPTIMISTIC"]>;
|
|
387
|
+
send<W extends keyof FinalExecutionOutcomeMap>(options: SendOptions<W>): Promise<FinalExecutionOutcomeMap[W]>;
|
|
388
|
+
}
|
|
389
|
+
export {};
|
|
390
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/core/transaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAUH,OAAO,EACL,KAAK,MAAM,EACX,KAAK,GAAG,EAGR,KAAK,UAAU,EAChB,MAAM,wBAAwB,CAAA;AAI/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAGL,KAAK,oBAAoB,EAI1B,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAEV,wBAAwB,EAExB,QAAQ,EACR,SAAS,EACT,WAAW,EAEX,MAAM,EACN,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,YAAY,CAAA;AAEnB;;GA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