@mentaproject/client 0.1.37 → 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/index.cjs CHANGED
@@ -146,7 +146,7 @@ __export(src_exports, {
146
146
  ContractManager: () => ContractManager,
147
147
  MemoryCache: () => MemoryCache,
148
148
  MentaClient: () => MentaClient,
149
- Transaction: () => Transaction,
149
+ Transaction: () => Transaction2,
150
150
  TransactionManager: () => TransactionManager,
151
151
  bigIntMax: () => bigIntMax,
152
152
  bigIntMin: () => bigIntMin,
@@ -157,14 +157,10 @@ __export(src_exports, {
157
157
  module.exports = __toCommonJS(src_exports);
158
158
 
159
159
  // src/structures/Account.ts
160
- var import_actions2 = require("@mentaproject/core/actions");
161
-
162
- // src/structures/Transaction.ts
163
160
  var import_actions = require("@mentaproject/core/actions");
161
+ var import_transactions = require("@mentaproject/transactions");
164
162
  var import_utils = require("@mentaproject/core/utils");
165
-
166
- // node_modules/viem/_esm/index.js
167
- init_transaction();
163
+ var import_contracts = require("@mentaproject/contracts");
168
164
 
169
165
  // src/utils/toJSON.ts
170
166
  function isClassInstance(obj) {
@@ -234,70 +230,126 @@ async function toJSON({ obj, depth = 0 }) {
234
230
  return convertBigintsToStrings(data);
235
231
  }
236
232
 
237
- // src/structures/Block.ts
238
- var Block = class {
239
- /**
240
- * @description Creates an instance of Block.
241
- * @param client - The instance of MentaClient used to interact with the blockchain.
242
- * @param data The raw block data conforming to IBlockData.
243
- * @param includeTransactions Whether to include full transaction objects. Defaults to false.
244
- */
245
- constructor(client, data) {
233
+ // src/structures/Account.ts
234
+ var Account = class {
235
+ constructor(client, data, persistenceManager) {
246
236
  this.client = client;
247
- this.baseFeePerGas = data.baseFeePerGas;
248
- this.blobGasUsed = data.blobGasUsed;
249
- this.difficulty = data.difficulty;
250
- this.excessBlobGas = data.excessBlobGas;
251
- this.extraData = data.extraData;
252
- this.gasLimit = data.gasLimit;
253
- this.gasUsed = data.gasUsed;
254
- this.hash = data.hash;
255
- this.logsBloom = data.logsBloom;
256
- this.mixHash = data.mixHash;
257
- this.nonce = data.nonce;
258
- this.number = data.number;
259
- this.parentBeaconBlockRoot = data.parentBeaconBlockRoot;
260
- this.parentHash = data.parentHash;
261
- this.receiptsRoot = data.receiptsRoot;
262
- this.sealFields = data.sealFields;
263
- this.sha3Uncles = data.sha3Uncles;
264
- this.size = data.size;
265
- this.stateRoot = data.stateRoot;
266
- this.timestamp = data.timestamp;
267
- this.totalDifficulty = data.totalDifficulty;
268
- this.transactionsRoot = data.transactionsRoot;
269
- this.uncles = data.uncles;
270
- this.withdrawals = data.withdrawals;
271
- this.withdrawalsRoot = data.withdrawalsRoot;
272
- this.miner = new Account(this.client, { address: data.miner });
273
- if (!data.transactions || data.transactions.length === 0) {
274
- const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new Transaction(this.client, data2));
275
- this.transactions = parsed;
276
- }
237
+ this.address = data.address;
238
+ this.persistenceManager = persistenceManager;
277
239
  }
278
- includeTransactions() {
279
- if (!this.transactions || this.transactions.length === 0) return false;
240
+ async isContract() {
241
+ const code = await (0, import_actions.getCode)(this.client.rpc, { address: this.address });
242
+ if (!code || code === "0x") return false;
280
243
  return true;
281
244
  }
245
+ async contractType() {
246
+ const isContract = await this.isContract();
247
+ if (!isContract) return void 0;
248
+ return await (0, import_contracts.getContractType)(this.client.rpc, this.address);
249
+ }
282
250
  /**
283
- * @description Converts the Block instance to a JSON representation.
284
- * This method serializes the block's properties into a plain JavaScript object,
285
- * suitable for JSON serialization.
286
- * @param depth The depth of the conversion. Defaults to 1.
287
- * @returns A promise that resolves to the JSON representation of the block.
251
+ * Creates a Transaction to send ETH to this account.
252
+ *
253
+ * @param amount The amount of ETH to send, in wei.
254
+ * @returns A Transaction with .call(), .simulate(), and .execute() methods.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * // Direct execution
259
+ * const pending = await account.sendEth(parseEther("1")).execute();
260
+ * const receipt = await pending.confirm();
261
+ *
262
+ * // Batch with MulticallTransaction
263
+ * multicall.addCall(account.sendEth(parseEther("1")));
264
+ * ```
288
265
  */
266
+ sendEth(amount) {
267
+ return new import_transactions.Transaction(this.client.rpc, {
268
+ to: this.address,
269
+ value: amount
270
+ });
271
+ }
272
+ async ETHBalance() {
273
+ return await (0, import_actions.getBalance)(this.client.rpc, { address: this.address });
274
+ }
275
+ async transactionCount() {
276
+ return await (0, import_actions.getTransactionCount)(this.client.rpc, { address: this.address });
277
+ }
278
+ async transactions(params, forceFetch = false) {
279
+ if (!this.persistenceManager || forceFetch) {
280
+ const hashes = await this._fetchTransactions(params);
281
+ const transactions = await Promise.all(
282
+ hashes.map((hash) => this.client.transactions.get({ hash }))
283
+ );
284
+ return transactions;
285
+ }
286
+ const jsons = await this.persistenceManager.getTransactions(
287
+ this.address,
288
+ params
289
+ );
290
+ return jsons.map((j) => this.client.transactions.parse(j));
291
+ }
292
+ async syncTransactions(limit = 1e3) {
293
+ if (!this.persistenceManager)
294
+ throw new Error("The persistence module is not configured.");
295
+ await this.persistenceManager.syncTransactions(this, limit);
296
+ }
297
+ async tokenTransactions(tokenAddress) {
298
+ if (!this.persistenceManager)
299
+ throw new Error("The persistence module is not configured.");
300
+ return {};
301
+ }
289
302
  async toJSON(depth) {
290
303
  return await toJSON({
291
304
  obj: {
292
- ...this
305
+ address: this.address,
306
+ isContract: this.isContract.bind(this),
307
+ contractType: this.contractType.bind(this),
308
+ ETHBalance: this.ETHBalance.bind(this),
309
+ transactionCount: this.transactionCount.bind(this)
293
310
  },
294
311
  depth
295
312
  });
296
313
  }
314
+ async _fetchTransactions({
315
+ fromBlock,
316
+ toBlock,
317
+ limit = 50
318
+ }) {
319
+ const lastBlock = await (0, import_actions.getBlockNumber)(this.client.rpc);
320
+ const onBlockRange = async ({ fromBlock: fromBlock2, toBlock: toBlock2 }, stop) => {
321
+ const outgoing = await (0, import_actions.traceFilter)(this.client.rpc, {
322
+ fromBlock: (0, import_utils.toHex)(fromBlock2),
323
+ toBlock: (0, import_utils.toHex)(toBlock2),
324
+ fromAddress: this.address
325
+ });
326
+ const incoming = await (0, import_actions.traceFilter)(this.client.rpc, {
327
+ fromBlock: (0, import_utils.toHex)(fromBlock2),
328
+ toBlock: (0, import_utils.toHex)(toBlock2),
329
+ toAddress: this.address
330
+ });
331
+ const traces = outgoing.concat(incoming).sort((a, b) => a.blockNumber - b.blockNumber);
332
+ return traces.map((t) => t.transactionHash);
333
+ };
334
+ return await (0, import_actions.fetchByBlockRange)({
335
+ toBlock: BigInt(toBlock !== void 0 ? toBlock : 0),
336
+ fromBlock: BigInt(fromBlock !== void 0 ? fromBlock : lastBlock),
337
+ direction: "backward",
338
+ itemLimit: limit,
339
+ onBlockRange
340
+ });
341
+ }
297
342
  };
298
343
 
299
344
  // src/structures/Transaction.ts
300
- var Transaction = class {
345
+ var import_actions2 = require("@mentaproject/core/actions");
346
+ var import_utils2 = require("@mentaproject/core/utils");
347
+
348
+ // node_modules/viem/_esm/index.js
349
+ init_transaction();
350
+
351
+ // src/structures/Transaction.ts
352
+ var Transaction2 = class {
301
353
  /**
302
354
  * Creates an instance of Transaction.
303
355
  * @description Initializes a new Transaction instance with the provided RPC client and transaction data.
@@ -334,15 +386,15 @@ var Transaction = class {
334
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.
335
387
  */
336
388
  async calls() {
337
- const traces = await (0, import_actions.traceTransaction)(this.client.rpc, this.hash);
389
+ const traces = await (0, import_actions2.traceTransaction)(this.client.rpc, this.hash);
338
390
  if (!traces) return void 0;
339
391
  const calls = traces.filter((t) => t.type === "call" && t.action !== void 0);
340
392
  return calls.map((c) => ({
341
393
  from: new Account(this.client, { address: c.action.from }),
342
394
  to: new Account(this.client, { address: c.action.to }),
343
- value: (0, import_utils.hexToBigInt)(c.action.value),
395
+ value: (0, import_utils2.hexToBigInt)(c.action.value),
344
396
  input: c.action.input,
345
- gas: (0, import_utils.hexToBigInt)(c.action.gas),
397
+ gas: (0, import_utils2.hexToBigInt)(c.action.gas),
346
398
  callType: c.action.callType
347
399
  }));
348
400
  }
@@ -353,7 +405,7 @@ var Transaction = class {
353
405
  * @returns {Promise<WaitForTransactionReceiptReturnType>} A promise that resolves to the transaction receipt once the specified number of confirmations are met.
354
406
  */
355
407
  async waitForReceipt(confirmations) {
356
- return await (0, import_actions.waitForTransactionReceipt)(this.client.rpc, {
408
+ return await (0, import_actions2.waitForTransactionReceipt)(this.client.rpc, {
357
409
  hash: this.hash,
358
410
  confirmations: confirmations || 1
359
411
  });
@@ -365,7 +417,7 @@ var Transaction = class {
365
417
  */
366
418
  async receipt() {
367
419
  try {
368
- return await (0, import_actions.getTransactionReceipt)(this.client.rpc, { hash: this.hash });
420
+ return await (0, import_actions2.getTransactionReceipt)(this.client.rpc, { hash: this.hash });
369
421
  } catch (error) {
370
422
  if (error instanceof TransactionReceiptNotFoundError) {
371
423
  return void 0;
@@ -378,7 +430,7 @@ var Transaction = class {
378
430
  * @returns {Promise<Block>} A promise that resolves to a Block instance representing the block that includes this transaction.
379
431
  */
380
432
  async block() {
381
- const data = await (0, import_actions.getBlock)(this.client.rpc, { blockHash: this.blockHash });
433
+ const data = await (0, import_actions2.getBlock)(this.client.rpc, { blockHash: this.blockHash });
382
434
  return new Block(this.client, data);
383
435
  }
384
436
  /**
@@ -404,187 +456,66 @@ var Transaction = class {
404
456
  }
405
457
  };
406
458
 
407
- // src/structures/Account.ts
408
- var import_utils2 = require("@mentaproject/core/utils");
409
- var import_contracts = require("@mentaproject/contracts");
410
- var Account = class {
459
+ // src/structures/Block.ts
460
+ var Block = class {
411
461
  /**
412
- * Creates an instance of the Account class.
413
- * @param client.rpc The CoreClient instance used for blockchain interactions.
414
- * @param address The blockchain address of the account.
415
- * @param persistenceManager An optional PersistenceManager instance for caching and data synchronization.
462
+ * @description Creates an instance of Block.
463
+ * @param client - The instance of MentaClient used to interact with the blockchain.
464
+ * @param data The raw block data conforming to IBlockData.
465
+ * @param includeTransactions Whether to include full transaction objects. Defaults to false.
416
466
  */
417
- constructor(client, data, persistenceManager) {
467
+ constructor(client, data) {
418
468
  this.client = client;
419
- this.address = data.address;
420
- this.persistenceManager = persistenceManager;
421
- }
422
- /**
423
- * Checks if the account's address belongs to a smart contract.
424
- * @description This method queries the blockchain for the code associated with the account's address.
425
- * If code is found, it indicates that the account is a contract.
426
- * @returns {Promise<boolean>} A promise that resolves to `true` if the account is a contract, `false` otherwise.
427
- */
428
- async isContract() {
429
- const code = await (0, import_actions2.getCode)(this.client.rpc, { address: this.address });
430
- if (!code || code === "0x") return false;
431
- return true;
432
- }
433
- /**
434
- * Retrieves the type of the contract if the account is a smart contract.
435
- * @description This method first checks if the account is a contract using `isContract()`.
436
- * If it is a contract, it then attempts to determine and return its type.
437
- * @returns {Promise<any>} A promise that resolves to the contract type (e.g., 'ERC20', 'ERC721') or `undefined` if the account is not a contract or its type cannot be determined.
438
- */
439
- async contractType() {
440
- const isContract = await this.isContract();
441
- if (!isContract) return void 0;
442
- return await (0, import_contracts.getContractType)(this.client.rpc, this.address);
443
- }
444
- /**
445
- * Sends a specified amount of native cryptocurrency (ETH) to this account.
446
- * @description This method constructs and sends a transaction to transfer ETH to the account's address.
447
- * @param {bigint} amount The amount of ETH to send, specified in wei (the smallest denomination of Ether).
448
- * @returns {Promise<Transaction>} A promise that resolves to a `Transaction` object representing the sent transaction.
449
- */
450
- async sendETH(amount) {
451
- const hash = await (0, import_actions2.sendTransaction)(this.client.rpc, {
452
- calls: [
453
- {
454
- to: this.address,
455
- value: amount
456
- }
457
- ]
458
- });
459
- const data = await (0, import_actions2.getTransaction)(this.client.rpc, { hash });
460
- return new Transaction(this.client, data);
461
- }
462
- /**
463
- * Retrieves the current native cryptocurrency (ETH) balance of the account.
464
- * @description This method queries the blockchain to get the balance associated with the account's address.
465
- * @returns {Promise<bigint>} A promise that resolves to the ETH balance of the account, in wei.
466
- */
467
- async ETHBalance() {
468
- return await (0, import_actions2.getBalance)(this.client.rpc, {
469
- address: this.address
470
- });
471
- }
472
- /**
473
- * Retrieves the transaction count (nonce) for the account.
474
- * @description The transaction count represents the number of transactions sent from this account,
475
- * which is also used as the nonce for new transactions to prevent replay attacks.
476
- * @returns {Promise<number>} A promise that resolves to the transaction count of the account.
477
- */
478
- async transactionCount() {
479
- return await (0, import_actions2.getTransactionCount)(this.client.rpc, {
480
- address: this.address
481
- });
482
- }
483
- /**
484
- * Retrieves all transactions involving this account.
485
- * @description If a `PersistenceManager` is configured, this method will first attempt to retrieve transactions from the local cache.
486
- * If not found in cache or if no `PersistenceManager` is configured, it will fetch transactions directly from the remote RPC.
487
- * @param {GetTransactionsOptions} [options] - Optional parameters for filtering, pagination, and sorting the transactions.
488
- * @param {number} [options.startBlock] - The starting block number (inclusive) from which to retrieve transactions.
489
- * @param {number} [options.endBlock] - The ending block number (inclusive) up to which to retrieve transactions.
490
- * @param {number} [options.page] - The page number for paginated results.
491
- * @param {number} [options.offset] - The number of items to skip from the beginning of the result set.
492
- * @param {'asc' | 'desc'} [options.sort] - The sorting order for transactions based on block number ('asc' for ascending, 'desc' for descending).
493
- * @param {boolean} [forceFetch=false] - Forces the method to fetch transactions from the remote source even if they are already cached. (mostly used internally)
494
- * @returns {Promise<Transaction[]>} A promise that resolves to an array of transactions.
495
- */
496
- async transactions(params, forceFetch = false) {
497
- if (!this.persistenceManager || forceFetch) {
498
- const hashes = await this._fetchTransactions(params);
499
- const transactions = await Promise.all(
500
- hashes.map((hash) => this.client.transactions.get({ hash }))
501
- );
502
- return transactions;
469
+ this.baseFeePerGas = data.baseFeePerGas;
470
+ this.blobGasUsed = data.blobGasUsed;
471
+ this.difficulty = data.difficulty;
472
+ this.excessBlobGas = data.excessBlobGas;
473
+ this.extraData = data.extraData;
474
+ this.gasLimit = data.gasLimit;
475
+ this.gasUsed = data.gasUsed;
476
+ this.hash = data.hash;
477
+ this.logsBloom = data.logsBloom;
478
+ this.mixHash = data.mixHash;
479
+ this.nonce = data.nonce;
480
+ this.number = data.number;
481
+ this.parentBeaconBlockRoot = data.parentBeaconBlockRoot;
482
+ this.parentHash = data.parentHash;
483
+ this.receiptsRoot = data.receiptsRoot;
484
+ this.sealFields = data.sealFields;
485
+ this.sha3Uncles = data.sha3Uncles;
486
+ this.size = data.size;
487
+ this.stateRoot = data.stateRoot;
488
+ this.timestamp = data.timestamp;
489
+ this.totalDifficulty = data.totalDifficulty;
490
+ this.transactionsRoot = data.transactionsRoot;
491
+ this.uncles = data.uncles;
492
+ this.withdrawals = data.withdrawals;
493
+ this.withdrawalsRoot = data.withdrawalsRoot;
494
+ this.miner = new Account(this.client, { address: data.miner });
495
+ if (!data.transactions || data.transactions.length === 0) {
496
+ const parsed = data.transactions.map((data2) => typeof data2 === "string" ? data2 : new Transaction2(this.client, data2));
497
+ this.transactions = parsed;
503
498
  }
504
- const jsons = await this.persistenceManager.getTransactions(
505
- this.address,
506
- params
507
- );
508
- return jsons.map((j) => this.client.transactions.parse(j));
509
- }
510
- /**
511
- * Synchronizes the account's transactions with the remote data source using the configured `PersistenceManager`.
512
- * @description This method initiates a synchronization process to ensure that the local cache of transactions
513
- * for this account is up-to-date with the blockchain.
514
- * @param {number} [limit] The maximum number of transactions to synchronize.
515
- * @returns {Promise<void>} A promise that resolves when the synchronization process is complete.
516
- * @throws {Error} If the persistence module is not configured.
517
- */
518
- async syncTransactions(limit = 1e3) {
519
- if (!this.persistenceManager)
520
- throw new Error("The persistence module is not configured.");
521
- await this.persistenceManager.syncTransactions(this, limit);
522
499
  }
523
- /**
524
- * Retrieves transactions involving a specific token. (not implemented yet)
525
- * @description This method queries the persistence adapter to retrieve transactions involving a specific token.
526
- * @param {Address} tokenAddress The address of the token.
527
- * @returns {Promise<any>} A promise that resolves to an array of transactions involving the token.
528
- * @throws {Error} If the persistence module is not configured.
529
- */
530
- async tokenTransactions(tokenAddress) {
531
- if (!this.persistenceManager)
532
- throw new Error("The persistence module is not configured.");
533
- return {};
500
+ includeTransactions() {
501
+ if (!this.transactions || this.transactions.length === 0) return false;
502
+ return true;
534
503
  }
535
504
  /**
536
- * Converts the Account instance into a JSON-serializable representation.
537
- * @description This method leverages a utility function to convert the `Account` object,
538
- * including its asynchronous properties (like `isContract`, `ETHBalance`), into a plain JSON object.
539
- * @param {number} [depth=1] The depth to which nested objects should be converted. A depth of 1 means only direct properties are included.
540
- * @returns {Promise<object>} A promise that resolves to the JSON representation of the account.
505
+ * @description Converts the Block instance to a JSON representation.
506
+ * This method serializes the block's properties into a plain JavaScript object,
507
+ * suitable for JSON serialization.
508
+ * @param depth The depth of the conversion. Defaults to 1.
509
+ * @returns A promise that resolves to the JSON representation of the block.
541
510
  */
542
511
  async toJSON(depth) {
543
512
  return await toJSON({
544
513
  obj: {
545
- address: this.address,
546
- isContract: this.isContract.bind(this),
547
- contractType: this.contractType.bind(this),
548
- ETHBalance: this.ETHBalance.bind(this),
549
- transactionCount: this.transactionCount.bind(this)
514
+ ...this
550
515
  },
551
516
  depth
552
517
  });
553
518
  }
554
- /**
555
- * Fetches transactions from the account using a block range exploration with trace_filter calls.
556
- *
557
- * @param params - The parameters for the block range exploration.
558
- * @returns A Promise that resolves to an array of transaction hashes.
559
- */
560
- async _fetchTransactions({
561
- fromBlock,
562
- toBlock,
563
- limit = 50
564
- }) {
565
- const lastBlock = await (0, import_actions2.getBlockNumber)(this.client.rpc);
566
- const onBlockRange = async ({ fromBlock: fromBlock2, toBlock: toBlock2 }, stop) => {
567
- const outgoing = await (0, import_actions2.traceFilter)(this.client.rpc, {
568
- fromBlock: (0, import_utils2.toHex)(fromBlock2),
569
- toBlock: (0, import_utils2.toHex)(toBlock2),
570
- fromAddress: this.address
571
- });
572
- const incoming = await (0, import_actions2.traceFilter)(this.client.rpc, {
573
- fromBlock: (0, import_utils2.toHex)(fromBlock2),
574
- toBlock: (0, import_utils2.toHex)(toBlock2),
575
- toAddress: this.address
576
- });
577
- const traces = outgoing.concat(incoming).sort((a, b) => a.blockNumber - b.blockNumber);
578
- return traces.map((t) => t.transactionHash);
579
- };
580
- return await (0, import_actions2.fetchByBlockRange)({
581
- toBlock: BigInt(toBlock !== void 0 ? toBlock : 0),
582
- fromBlock: BigInt(fromBlock !== void 0 ? fromBlock : lastBlock),
583
- direction: "backward",
584
- itemLimit: limit,
585
- onBlockRange
586
- });
587
- }
588
519
  };
589
520
 
590
521
  // src/structures/MentaClient.ts
@@ -636,6 +567,7 @@ var BlockManager = class {
636
567
  };
637
568
 
638
569
  // src/managers/TransactionManager.ts
570
+ var import_transactions2 = require("@mentaproject/transactions");
639
571
  var import_actions4 = require("@mentaproject/core/actions");
640
572
 
641
573
  // src/utils/bigint.ts
@@ -692,36 +624,49 @@ function parseBingints(obj) {
692
624
 
693
625
  // src/managers/TransactionManager.ts
694
626
  var TransactionManager = class {
695
- /**
696
- * Creates an instance of `TransactionManager`.
697
- * @constructor
698
- * @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.
699
- */
700
627
  constructor(client) {
701
628
  this.client = client;
702
629
  }
703
630
  /**
704
- * Retrieves a transaction by its hash or block number and index.
705
- * @description This method fetches detailed information about a specific transaction
706
- * from the blockchain using the provided parameters.
707
- * @param {GetTransactionParameters} params - The parameters for retrieving the transaction,
708
- * typically including `hash` or `blockNumber` and `index`.
709
- * @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
710
- * containing the retrieved transaction data.
631
+ * Creates a new MulticallTransaction for batching multiple calls.
632
+ *
633
+ * @returns A MulticallTransaction builder
634
+ *
635
+ * @example
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
+ *
711
652
  * @example
712
- * const txHash = '0x...'; // Replace with a valid transaction hash
713
- * const transaction = await client.transactions.get({ hash: txHash });
714
- * console.log(transaction);
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.
715
663
  */
716
664
  async get(params) {
717
665
  const data = await (0, import_actions4.getTransaction)(this.client.rpc, params);
718
- return new Transaction(this.client, data);
666
+ return new Transaction2(this.client, data);
719
667
  }
720
668
  /**
721
669
  * Parse a transaction object from a JSON converted transaction data object.
722
- *
723
- * @param {J} data - The JSON converted transaction data object.
724
- * @returns {Transaction} A Transaction instance representing the parsed transaction.
725
670
  */
726
671
  parse(data) {
727
672
  const parsed = parseBingints(data);
@@ -730,32 +675,11 @@ var TransactionManager = class {
730
675
  from: parsed.from.address,
731
676
  to: parsed.to ? parsed.to.address : null
732
677
  };
733
- return new Transaction(this.client, rawData);
678
+ return new Transaction2(this.client, rawData);
734
679
  }
735
680
  /**
736
681
  * Sends a transaction to the blockchain network.
737
- * @description This method submits a new transaction to the blockchain. After the transaction
738
- * is successfully sent, it retrieves and returns the full transaction details.
739
- * @param {SendTransactionParameters} params - The parameters required to send the transaction,
740
- * such as `to`, `value`, `data`, `gasLimit`, etc.
741
- * @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
742
- * representing the sent transaction, including its hash and other details.
743
- * @example
744
- * import { MentaClient } from '@mentaproject/client';
745
- * import { http } from '@mentaproject/core';
746
- *
747
- * // This example assumes you have an account with funds, which is available to the client.
748
- * const client = new MentaClient({
749
- * chain: 'mainnet',
750
- * transport: http('http://rpcurlhere.com')
751
- * });
752
- *
753
- * const transactionResult = await client.transactions.send({
754
- * to: '0xRecipientAddress...', // Replace with a valid recipient address
755
- * value: 1000000000000000000n, // 1 ETH in wei
756
- * });
757
- *
758
- * console.log('Transaction sent with hash:', transactionResult.hash);
682
+ * @deprecated Use client.transactions.create() for new transactions
759
683
  */
760
684
  async send(params) {
761
685
  const hash = await (0, import_actions4.sendTransaction)(this.client.rpc, params);