@mentaproject/client 0.1.38 → 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/dist/.tsbuildinfo +1 -1
- package/dist/index.cjs +70 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -83
- package/dist/index.js.map +1 -1
- package/dist/managers/TransactionManager.d.ts +48 -48
- package/dist/structures/Account.d.ts +10 -9
- package/dist/structures/Action.d.ts +20 -4
- package/dist/structures/index.d.ts +0 -1
- package/package.json +2 -1
- package/src/managers/TransactionManager.ts +81 -76
- package/src/structures/Account.ts +11 -10
- package/src/structures/index.ts +0 -1
- package/src/structures/Action.ts +0 -51
package/dist/index.cjs
CHANGED
|
@@ -141,13 +141,12 @@ var src_exports = {};
|
|
|
141
141
|
__export(src_exports, {
|
|
142
142
|
Account: () => Account,
|
|
143
143
|
AccountManager: () => AccountManager,
|
|
144
|
-
Action: () => Action,
|
|
145
144
|
Block: () => Block,
|
|
146
145
|
BlockManager: () => BlockManager,
|
|
147
146
|
ContractManager: () => ContractManager,
|
|
148
147
|
MemoryCache: () => MemoryCache,
|
|
149
148
|
MentaClient: () => MentaClient,
|
|
150
|
-
Transaction: () =>
|
|
149
|
+
Transaction: () => Transaction2,
|
|
151
150
|
TransactionManager: () => TransactionManager,
|
|
152
151
|
bigIntMax: () => bigIntMax,
|
|
153
152
|
bigIntMin: () => bigIntMin,
|
|
@@ -158,38 +157,8 @@ __export(src_exports, {
|
|
|
158
157
|
module.exports = __toCommonJS(src_exports);
|
|
159
158
|
|
|
160
159
|
// src/structures/Account.ts
|
|
161
|
-
var import_actions2 = require("@mentaproject/core/actions");
|
|
162
|
-
|
|
163
|
-
// src/structures/Action.ts
|
|
164
160
|
var import_actions = require("@mentaproject/core/actions");
|
|
165
|
-
var
|
|
166
|
-
constructor(client, _call) {
|
|
167
|
-
this.client = client;
|
|
168
|
-
this._call = _call;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Returns the Call object for use with TransactionBuilder.
|
|
172
|
-
*/
|
|
173
|
-
call() {
|
|
174
|
-
return this._call;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Simulates the action without executing.
|
|
178
|
-
*/
|
|
179
|
-
async simulate() {
|
|
180
|
-
return (0, import_actions.simulateCalls)(this.client, { calls: [this._call] });
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Executes the action directly.
|
|
184
|
-
*
|
|
185
|
-
* @returns Transaction hash
|
|
186
|
-
*/
|
|
187
|
-
async execute() {
|
|
188
|
-
return this.client.sendTransaction(this._call);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// src/structures/Account.ts
|
|
161
|
+
var import_transactions = require("@mentaproject/transactions");
|
|
193
162
|
var import_utils = require("@mentaproject/core/utils");
|
|
194
163
|
var import_contracts = require("@mentaproject/contracts");
|
|
195
164
|
|
|
@@ -269,7 +238,7 @@ var Account = class {
|
|
|
269
238
|
this.persistenceManager = persistenceManager;
|
|
270
239
|
}
|
|
271
240
|
async isContract() {
|
|
272
|
-
const code = await (0,
|
|
241
|
+
const code = await (0, import_actions.getCode)(this.client.rpc, { address: this.address });
|
|
273
242
|
if (!code || code === "0x") return false;
|
|
274
243
|
return true;
|
|
275
244
|
}
|
|
@@ -279,31 +248,32 @@ var Account = class {
|
|
|
279
248
|
return await (0, import_contracts.getContractType)(this.client.rpc, this.address);
|
|
280
249
|
}
|
|
281
250
|
/**
|
|
282
|
-
* Creates
|
|
251
|
+
* Creates a Transaction to send ETH to this account.
|
|
283
252
|
*
|
|
284
253
|
* @param amount The amount of ETH to send, in wei.
|
|
285
|
-
* @returns
|
|
254
|
+
* @returns A Transaction with .call(), .simulate(), and .execute() methods.
|
|
286
255
|
*
|
|
287
256
|
* @example
|
|
288
257
|
* ```ts
|
|
289
258
|
* // Direct execution
|
|
290
|
-
* await account.sendEth(parseEther("1")).execute();
|
|
259
|
+
* const pending = await account.sendEth(parseEther("1")).execute();
|
|
260
|
+
* const receipt = await pending.confirm();
|
|
291
261
|
*
|
|
292
|
-
* // Batch with
|
|
293
|
-
*
|
|
262
|
+
* // Batch with MulticallTransaction
|
|
263
|
+
* multicall.addCall(account.sendEth(parseEther("1")));
|
|
294
264
|
* ```
|
|
295
265
|
*/
|
|
296
266
|
sendEth(amount) {
|
|
297
|
-
return new
|
|
267
|
+
return new import_transactions.Transaction(this.client.rpc, {
|
|
298
268
|
to: this.address,
|
|
299
269
|
value: amount
|
|
300
270
|
});
|
|
301
271
|
}
|
|
302
272
|
async ETHBalance() {
|
|
303
|
-
return await (0,
|
|
273
|
+
return await (0, import_actions.getBalance)(this.client.rpc, { address: this.address });
|
|
304
274
|
}
|
|
305
275
|
async transactionCount() {
|
|
306
|
-
return await (0,
|
|
276
|
+
return await (0, import_actions.getTransactionCount)(this.client.rpc, { address: this.address });
|
|
307
277
|
}
|
|
308
278
|
async transactions(params, forceFetch = false) {
|
|
309
279
|
if (!this.persistenceManager || forceFetch) {
|
|
@@ -346,14 +316,14 @@ var Account = class {
|
|
|
346
316
|
toBlock,
|
|
347
317
|
limit = 50
|
|
348
318
|
}) {
|
|
349
|
-
const lastBlock = await (0,
|
|
319
|
+
const lastBlock = await (0, import_actions.getBlockNumber)(this.client.rpc);
|
|
350
320
|
const onBlockRange = async ({ fromBlock: fromBlock2, toBlock: toBlock2 }, stop) => {
|
|
351
|
-
const outgoing = await (0,
|
|
321
|
+
const outgoing = await (0, import_actions.traceFilter)(this.client.rpc, {
|
|
352
322
|
fromBlock: (0, import_utils.toHex)(fromBlock2),
|
|
353
323
|
toBlock: (0, import_utils.toHex)(toBlock2),
|
|
354
324
|
fromAddress: this.address
|
|
355
325
|
});
|
|
356
|
-
const incoming = await (0,
|
|
326
|
+
const incoming = await (0, import_actions.traceFilter)(this.client.rpc, {
|
|
357
327
|
fromBlock: (0, import_utils.toHex)(fromBlock2),
|
|
358
328
|
toBlock: (0, import_utils.toHex)(toBlock2),
|
|
359
329
|
toAddress: this.address
|
|
@@ -361,7 +331,7 @@ var Account = class {
|
|
|
361
331
|
const traces = outgoing.concat(incoming).sort((a, b) => a.blockNumber - b.blockNumber);
|
|
362
332
|
return traces.map((t) => t.transactionHash);
|
|
363
333
|
};
|
|
364
|
-
return await (0,
|
|
334
|
+
return await (0, import_actions.fetchByBlockRange)({
|
|
365
335
|
toBlock: BigInt(toBlock !== void 0 ? toBlock : 0),
|
|
366
336
|
fromBlock: BigInt(fromBlock !== void 0 ? fromBlock : lastBlock),
|
|
367
337
|
direction: "backward",
|
|
@@ -372,14 +342,14 @@ var Account = class {
|
|
|
372
342
|
};
|
|
373
343
|
|
|
374
344
|
// src/structures/Transaction.ts
|
|
375
|
-
var
|
|
345
|
+
var import_actions2 = require("@mentaproject/core/actions");
|
|
376
346
|
var import_utils2 = require("@mentaproject/core/utils");
|
|
377
347
|
|
|
378
348
|
// node_modules/viem/_esm/index.js
|
|
379
349
|
init_transaction();
|
|
380
350
|
|
|
381
351
|
// src/structures/Transaction.ts
|
|
382
|
-
var
|
|
352
|
+
var Transaction2 = class {
|
|
383
353
|
/**
|
|
384
354
|
* Creates an instance of Transaction.
|
|
385
355
|
* @description Initializes a new Transaction instance with the provided RPC client and transaction data.
|
|
@@ -416,7 +386,7 @@ var Transaction = class {
|
|
|
416
386
|
* @returns {Promise<TransactionCall[] | undefined>} A promise that resolves to an array of call objects, each representing an internal call with sender, recipient, value, input data, gas used, and call type.
|
|
417
387
|
*/
|
|
418
388
|
async calls() {
|
|
419
|
-
const traces = await (0,
|
|
389
|
+
const traces = await (0, import_actions2.traceTransaction)(this.client.rpc, this.hash);
|
|
420
390
|
if (!traces) return void 0;
|
|
421
391
|
const calls = traces.filter((t) => t.type === "call" && t.action !== void 0);
|
|
422
392
|
return calls.map((c) => ({
|
|
@@ -435,7 +405,7 @@ var Transaction = class {
|
|
|
435
405
|
* @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt once the specified number of confirmations are met.
|
|
436
406
|
*/
|
|
437
407
|
async waitForReceipt(confirmations) {
|
|
438
|
-
return await (0,
|
|
408
|
+
return await (0, import_actions2.waitForTransactionReceipt)(this.client.rpc, {
|
|
439
409
|
hash: this.hash,
|
|
440
410
|
confirmations: confirmations || 1
|
|
441
411
|
});
|
|
@@ -447,7 +417,7 @@ var Transaction = class {
|
|
|
447
417
|
*/
|
|
448
418
|
async receipt() {
|
|
449
419
|
try {
|
|
450
|
-
return await (0,
|
|
420
|
+
return await (0, import_actions2.getTransactionReceipt)(this.client.rpc, { hash: this.hash });
|
|
451
421
|
} catch (error) {
|
|
452
422
|
if (error instanceof TransactionReceiptNotFoundError) {
|
|
453
423
|
return void 0;
|
|
@@ -460,7 +430,7 @@ var Transaction = class {
|
|
|
460
430
|
* @returns {Promise<Block>} A promise that resolves to a Block instance representing the block that includes this transaction.
|
|
461
431
|
*/
|
|
462
432
|
async block() {
|
|
463
|
-
const data = await (0,
|
|
433
|
+
const data = await (0, import_actions2.getBlock)(this.client.rpc, { blockHash: this.blockHash });
|
|
464
434
|
return new Block(this.client, data);
|
|
465
435
|
}
|
|
466
436
|
/**
|
|
@@ -523,7 +493,7 @@ var Block = class {
|
|
|
523
493
|
this.withdrawalsRoot = data.withdrawalsRoot;
|
|
524
494
|
this.miner = new Account(this.client, { address: data.miner });
|
|
525
495
|
if (!data.transactions || data.transactions.length === 0) {
|
|
526
|
-
const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new
|
|
496
|
+
const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new Transaction2(this.client, data2));
|
|
527
497
|
this.transactions = parsed;
|
|
528
498
|
}
|
|
529
499
|
}
|
|
@@ -553,7 +523,7 @@ var import_clients = require("@mentaproject/core/clients");
|
|
|
553
523
|
var import_core = require("@mentaproject/core");
|
|
554
524
|
|
|
555
525
|
// src/managers/BlockManager.ts
|
|
556
|
-
var
|
|
526
|
+
var import_actions3 = require("@mentaproject/core/actions");
|
|
557
527
|
var BlockManager = class {
|
|
558
528
|
/**
|
|
559
529
|
* Creates an instance of BlockManager.
|
|
@@ -591,13 +561,14 @@ var BlockManager = class {
|
|
|
591
561
|
* fetchBlock();
|
|
592
562
|
*/
|
|
593
563
|
async get(params) {
|
|
594
|
-
const data = await (0,
|
|
564
|
+
const data = await (0, import_actions3.getBlock)(this.client.rpc, params);
|
|
595
565
|
return new Block(this.client, data);
|
|
596
566
|
}
|
|
597
567
|
};
|
|
598
568
|
|
|
599
569
|
// src/managers/TransactionManager.ts
|
|
600
|
-
var
|
|
570
|
+
var import_transactions2 = require("@mentaproject/transactions");
|
|
571
|
+
var import_actions4 = require("@mentaproject/core/actions");
|
|
601
572
|
|
|
602
573
|
// src/utils/bigint.ts
|
|
603
574
|
var bigIntMax = (...args) => args.reduce((m, e) => e > m ? e : m);
|
|
@@ -653,36 +624,49 @@ function parseBingints(obj) {
|
|
|
653
624
|
|
|
654
625
|
// src/managers/TransactionManager.ts
|
|
655
626
|
var TransactionManager = class {
|
|
656
|
-
/**
|
|
657
|
-
* Creates an instance of `TransactionManager`.
|
|
658
|
-
* @constructor
|
|
659
|
-
* @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.
|
|
660
|
-
*/
|
|
661
627
|
constructor(client) {
|
|
662
628
|
this.client = client;
|
|
663
629
|
}
|
|
664
630
|
/**
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
* typically including `hash` or `blockNumber` and `index`.
|
|
670
|
-
* @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
|
|
671
|
-
* containing the retrieved transaction data.
|
|
631
|
+
* Creates a new MulticallTransaction for batching multiple calls.
|
|
632
|
+
*
|
|
633
|
+
* @returns A MulticallTransaction builder
|
|
634
|
+
*
|
|
672
635
|
* @example
|
|
673
|
-
*
|
|
674
|
-
* const
|
|
675
|
-
*
|
|
636
|
+
* ```ts
|
|
637
|
+
* const pending = await client.transactions.create()
|
|
638
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
639
|
+
* .addCall(erc20.transfer(to, amount))
|
|
640
|
+
* .execute();
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
create() {
|
|
644
|
+
return new import_transactions2.MulticallTransaction(this.client.rpc);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Retrieves a rich transaction by its hash.
|
|
648
|
+
*
|
|
649
|
+
* @param hash - The transaction hash
|
|
650
|
+
* @returns A rich Transaction with receipt, block, etc.
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* ```ts
|
|
654
|
+
* const tx = await client.transactions.fromHash(hash);
|
|
655
|
+
* console.log(tx.from, tx.to, tx.value);
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
async fromHash(hash) {
|
|
659
|
+
return this.get({ hash });
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Retrieves a transaction by its hash or block number and index.
|
|
676
663
|
*/
|
|
677
664
|
async get(params) {
|
|
678
|
-
const data = await (0,
|
|
679
|
-
return new
|
|
665
|
+
const data = await (0, import_actions4.getTransaction)(this.client.rpc, params);
|
|
666
|
+
return new Transaction2(this.client, data);
|
|
680
667
|
}
|
|
681
668
|
/**
|
|
682
669
|
* Parse a transaction object from a JSON converted transaction data object.
|
|
683
|
-
*
|
|
684
|
-
* @param {J} data - The JSON converted transaction data object.
|
|
685
|
-
* @returns {Transaction} A Transaction instance representing the parsed transaction.
|
|
686
670
|
*/
|
|
687
671
|
parse(data) {
|
|
688
672
|
const parsed = parseBingints(data);
|
|
@@ -691,35 +675,14 @@ var TransactionManager = class {
|
|
|
691
675
|
from: parsed.from.address,
|
|
692
676
|
to: parsed.to ? parsed.to.address : null
|
|
693
677
|
};
|
|
694
|
-
return new
|
|
678
|
+
return new Transaction2(this.client, rawData);
|
|
695
679
|
}
|
|
696
680
|
/**
|
|
697
681
|
* Sends a transaction to the blockchain network.
|
|
698
|
-
* @
|
|
699
|
-
* is successfully sent, it retrieves and returns the full transaction details.
|
|
700
|
-
* @param {SendTransactionParameters} params - The parameters required to send the transaction,
|
|
701
|
-
* such as `to`, `value`, `data`, `gasLimit`, etc.
|
|
702
|
-
* @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
|
|
703
|
-
* representing the sent transaction, including its hash and other details.
|
|
704
|
-
* @example
|
|
705
|
-
* import { MentaClient } from '@mentaproject/client';
|
|
706
|
-
* import { http } from '@mentaproject/core';
|
|
707
|
-
*
|
|
708
|
-
* // This example assumes you have an account with funds, which is available to the client.
|
|
709
|
-
* const client = new MentaClient({
|
|
710
|
-
* chain: 'mainnet',
|
|
711
|
-
* transport: http('http://rpcurlhere.com')
|
|
712
|
-
* });
|
|
713
|
-
*
|
|
714
|
-
* const transactionResult = await client.transactions.send({
|
|
715
|
-
* to: '0xRecipientAddress...', // Replace with a valid recipient address
|
|
716
|
-
* value: 1000000000000000000n, // 1 ETH in wei
|
|
717
|
-
* });
|
|
718
|
-
*
|
|
719
|
-
* console.log('Transaction sent with hash:', transactionResult.hash);
|
|
682
|
+
* @deprecated Use client.transactions.create() for new transactions
|
|
720
683
|
*/
|
|
721
684
|
async send(params) {
|
|
722
|
-
const hash = await (0,
|
|
685
|
+
const hash = await (0, import_actions4.sendTransaction)(this.client.rpc, params);
|
|
723
686
|
return await this.get({ hash });
|
|
724
687
|
}
|
|
725
688
|
};
|
|
@@ -817,7 +780,7 @@ var AccountManager = class {
|
|
|
817
780
|
};
|
|
818
781
|
|
|
819
782
|
// src/managers/PersistenceManager.ts
|
|
820
|
-
var
|
|
783
|
+
var import_actions5 = require("@mentaproject/core/actions");
|
|
821
784
|
var PersistenceManager = class {
|
|
822
785
|
/**
|
|
823
786
|
* Creates an instance of PersistenceManager.
|
|
@@ -846,7 +809,7 @@ var PersistenceManager = class {
|
|
|
846
809
|
async syncTransactions(account, limit = 1e5) {
|
|
847
810
|
const lastSyncedBlock = await this.persistenceAdapter.getLastSyncedBlock(account.address);
|
|
848
811
|
const lastBlock = lastSyncedBlock ?? 0n;
|
|
849
|
-
const fromBlock = lastSyncedBlock ? lastSyncedBlock + 1n : await (0,
|
|
812
|
+
const fromBlock = lastSyncedBlock ? lastSyncedBlock + 1n : await (0, import_actions5.getBlockNumber)(this.client.rpc);
|
|
850
813
|
const newTransactions = await account.transactions({
|
|
851
814
|
fromBlock,
|
|
852
815
|
toBlock: lastBlock,
|
|
@@ -861,22 +824,22 @@ var PersistenceManager = class {
|
|
|
861
824
|
};
|
|
862
825
|
|
|
863
826
|
// src/types/MentaClient.ts
|
|
864
|
-
var
|
|
827
|
+
var import_actions6 = require("@mentaproject/core/actions");
|
|
865
828
|
var ClientEvents = {
|
|
866
829
|
/**
|
|
867
830
|
* Event for new blocks.
|
|
868
831
|
* Uses the {@link watchBlocks} function from `@mentaproject/core`.
|
|
869
832
|
*/
|
|
870
|
-
block:
|
|
833
|
+
block: import_actions6.watchBlocks,
|
|
871
834
|
/**
|
|
872
835
|
* Event for new block numbers.
|
|
873
836
|
* Uses the {@link watchBlockNumber} function from `@mentaproject/core`.
|
|
874
837
|
*/
|
|
875
|
-
blockNumber:
|
|
838
|
+
blockNumber: import_actions6.watchBlockNumber
|
|
876
839
|
};
|
|
877
840
|
|
|
878
841
|
// src/utils/withCache.ts
|
|
879
|
-
var
|
|
842
|
+
var import_actions7 = require("@mentaproject/core/actions");
|
|
880
843
|
var GET_NONCE_SELECTOR = "0x35567e1a";
|
|
881
844
|
function isNonceCall(method, params) {
|
|
882
845
|
if (method !== "eth_call") return false;
|
|
@@ -884,7 +847,7 @@ function isNonceCall(method, params) {
|
|
|
884
847
|
return typeof callData === "string" && callData.startsWith(GET_NONCE_SELECTOR);
|
|
885
848
|
}
|
|
886
849
|
function withCache(client, cache) {
|
|
887
|
-
(0,
|
|
850
|
+
(0, import_actions7.watchBlockNumber)(client, {
|
|
888
851
|
onBlockNumber: (blockNumber) => {
|
|
889
852
|
cache.setBlockNumber(blockNumber);
|
|
890
853
|
},
|
|
@@ -1112,7 +1075,6 @@ var MemoryCache = class {
|
|
|
1112
1075
|
0 && (module.exports = {
|
|
1113
1076
|
Account,
|
|
1114
1077
|
AccountManager,
|
|
1115
|
-
Action,
|
|
1116
1078
|
Block,
|
|
1117
1079
|
BlockManager,
|
|
1118
1080
|
ContractManager,
|