@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
|
@@ -2,69 +2,69 @@
|
|
|
2
2
|
* @module TransactionManager
|
|
3
3
|
*/
|
|
4
4
|
import { GetTransactionParameters, SendTransactionParameters } from "@mentaproject/core/types";
|
|
5
|
-
import { Transaction } from "../structures/Transaction";
|
|
5
|
+
import { Transaction as RichTransaction } from "../structures/Transaction";
|
|
6
|
+
import { MulticallTransaction } from "@mentaproject/transactions";
|
|
6
7
|
import { MentaClient } from "../structures";
|
|
7
8
|
import { JSONTransaction } from "../types";
|
|
8
9
|
/**
|
|
9
|
-
* Manages blockchain transaction-related operations
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Manages blockchain transaction-related operations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // Create a multicall transaction
|
|
15
|
+
* const pending = await client.transactions.create()
|
|
16
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
17
|
+
* .addCall(erc20.transfer(to, amount))
|
|
18
|
+
* .execute();
|
|
19
|
+
*
|
|
20
|
+
* const receipt = await pending.confirm();
|
|
21
|
+
*
|
|
22
|
+
* // Get a transaction by hash
|
|
23
|
+
* const tx = await client.transactions.fromHash(hash);
|
|
24
|
+
* console.log(tx.receipt, tx.block);
|
|
25
|
+
* ```
|
|
14
26
|
*/
|
|
15
27
|
export declare class TransactionManager {
|
|
16
28
|
client: MentaClient;
|
|
29
|
+
constructor(client: MentaClient);
|
|
17
30
|
/**
|
|
18
|
-
* Creates
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
31
|
+
* Creates a new MulticallTransaction for batching multiple calls.
|
|
32
|
+
*
|
|
33
|
+
* @returns A MulticallTransaction builder
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const pending = await client.transactions.create()
|
|
38
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
39
|
+
* .addCall(erc20.transfer(to, amount))
|
|
40
|
+
* .execute();
|
|
41
|
+
* ```
|
|
21
42
|
*/
|
|
22
|
-
|
|
43
|
+
create(): MulticallTransaction;
|
|
23
44
|
/**
|
|
24
|
-
* Retrieves a transaction by its hash
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
28
|
-
*
|
|
29
|
-
* @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
|
|
30
|
-
* containing the retrieved transaction data.
|
|
45
|
+
* Retrieves a rich transaction by its hash.
|
|
46
|
+
*
|
|
47
|
+
* @param hash - The transaction hash
|
|
48
|
+
* @returns A rich Transaction with receipt, block, etc.
|
|
49
|
+
*
|
|
31
50
|
* @example
|
|
32
|
-
*
|
|
33
|
-
* const
|
|
34
|
-
* console.log(
|
|
51
|
+
* ```ts
|
|
52
|
+
* const tx = await client.transactions.fromHash(hash);
|
|
53
|
+
* console.log(tx.from, tx.to, tx.value);
|
|
54
|
+
* ```
|
|
35
55
|
*/
|
|
36
|
-
|
|
56
|
+
fromHash(hash: `0x${string}`): Promise<RichTransaction>;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves a transaction by its hash or block number and index.
|
|
59
|
+
*/
|
|
60
|
+
get(params: GetTransactionParameters): Promise<RichTransaction>;
|
|
37
61
|
/**
|
|
38
62
|
* Parse a transaction object from a JSON converted transaction data object.
|
|
39
|
-
*
|
|
40
|
-
* @param {J} data - The JSON converted transaction data object.
|
|
41
|
-
* @returns {Transaction} A Transaction instance representing the parsed transaction.
|
|
42
63
|
*/
|
|
43
|
-
parse<J extends JSONTransaction<0>>(data: J):
|
|
64
|
+
parse<J extends JSONTransaction<0>>(data: J): RichTransaction;
|
|
44
65
|
/**
|
|
45
66
|
* Sends a transaction to the blockchain network.
|
|
46
|
-
* @
|
|
47
|
-
* is successfully sent, it retrieves and returns the full transaction details.
|
|
48
|
-
* @param {SendTransactionParameters} params - The parameters required to send the transaction,
|
|
49
|
-
* such as `to`, `value`, `data`, `gasLimit`, etc.
|
|
50
|
-
* @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
|
|
51
|
-
* representing the sent transaction, including its hash and other details.
|
|
52
|
-
* @example
|
|
53
|
-
* import { MentaClient } from '@mentaproject/client';
|
|
54
|
-
* import { http } from '@mentaproject/core';
|
|
55
|
-
*
|
|
56
|
-
* // This example assumes you have an account with funds, which is available to the client.
|
|
57
|
-
* const client = new MentaClient({
|
|
58
|
-
* chain: 'mainnet',
|
|
59
|
-
* transport: http('http://rpcurlhere.com')
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* const transactionResult = await client.transactions.send({
|
|
63
|
-
* to: '0xRecipientAddress...', // Replace with a valid recipient address
|
|
64
|
-
* value: 1000000000000000000n, // 1 ETH in wei
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* console.log('Transaction sent with hash:', transactionResult.hash);
|
|
67
|
+
* @deprecated Use client.transactions.create() for new transactions
|
|
68
68
|
*/
|
|
69
|
-
send(params: SendTransactionParameters): Promise<
|
|
69
|
+
send(params: SendTransactionParameters): Promise<RichTransaction>;
|
|
70
70
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address, Hash } from "@mentaproject/core/types";
|
|
2
|
-
import { Transaction } from "./Transaction";
|
|
3
|
-
import {
|
|
2
|
+
import { Transaction as RichTransaction } from "./Transaction";
|
|
3
|
+
import { Transaction } from "@mentaproject/transactions";
|
|
4
4
|
import { AccountData, FetchTransactionParams, GetTransactionsParams, JSONAccount } from "../types/Account";
|
|
5
5
|
import { PersistenceManager } from "../managers/PersistenceManager";
|
|
6
6
|
import { MentaClient } from "./MentaClient";
|
|
@@ -15,24 +15,25 @@ export declare class Account implements AccountData {
|
|
|
15
15
|
isContract(): Promise<boolean>;
|
|
16
16
|
contractType(): Promise<any>;
|
|
17
17
|
/**
|
|
18
|
-
* Creates
|
|
18
|
+
* Creates a Transaction to send ETH to this account.
|
|
19
19
|
*
|
|
20
20
|
* @param amount The amount of ETH to send, in wei.
|
|
21
|
-
* @returns
|
|
21
|
+
* @returns A Transaction with .call(), .simulate(), and .execute() methods.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* ```ts
|
|
25
25
|
* // Direct execution
|
|
26
|
-
* await account.sendEth(parseEther("1")).execute();
|
|
26
|
+
* const pending = await account.sendEth(parseEther("1")).execute();
|
|
27
|
+
* const receipt = await pending.confirm();
|
|
27
28
|
*
|
|
28
|
-
* // Batch with
|
|
29
|
-
*
|
|
29
|
+
* // Batch with MulticallTransaction
|
|
30
|
+
* multicall.addCall(account.sendEth(parseEther("1")));
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
sendEth(amount: bigint):
|
|
33
|
+
sendEth(amount: bigint): Transaction;
|
|
33
34
|
ETHBalance(): Promise<bigint>;
|
|
34
35
|
transactionCount(): Promise<number>;
|
|
35
|
-
transactions(params: GetTransactionsParams, forceFetch?: boolean): Promise<
|
|
36
|
+
transactions(params: GetTransactionsParams, forceFetch?: boolean): Promise<RichTransaction[]>;
|
|
36
37
|
syncTransactions(limit?: number): Promise<void>;
|
|
37
38
|
tokenTransactions(tokenAddress: Address): Promise<any>;
|
|
38
39
|
toJSON<D extends number = 1>(depth: D): Promise<JSONAccount<D>>;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import { Call, Hex } from "@mentaproject/core";
|
|
1
|
+
import { Call, Hex, TransactionReceipt } from "@mentaproject/core";
|
|
2
2
|
import { MentaAccountClient } from "@mentaproject/core/types";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a transaction that has been sent but not yet confirmed.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PendingTransaction {
|
|
7
|
+
private client;
|
|
8
|
+
readonly hash: Hex;
|
|
9
|
+
constructor(client: MentaAccountClient, hash: Hex);
|
|
10
|
+
/**
|
|
11
|
+
* Waits for the transaction to be confirmed.
|
|
12
|
+
*
|
|
13
|
+
* @param confirmations Number of block confirmations to wait for (default: 1)
|
|
14
|
+
* @returns The transaction receipt
|
|
15
|
+
*/
|
|
16
|
+
confirm(confirmations?: number): Promise<TransactionReceipt>;
|
|
17
|
+
}
|
|
3
18
|
/**
|
|
4
19
|
* Generic action object that wraps a single call.
|
|
5
20
|
*
|
|
@@ -9,7 +24,8 @@ import { MentaAccountClient } from "@mentaproject/core/types";
|
|
|
9
24
|
* @example
|
|
10
25
|
* ```ts
|
|
11
26
|
* // Direct execution
|
|
12
|
-
* await account.sendEth(parseEther("1")).execute();
|
|
27
|
+
* const pending = await account.sendEth(parseEther("1")).execute();
|
|
28
|
+
* const receipt = await pending.confirm();
|
|
13
29
|
*
|
|
14
30
|
* // Batching with TransactionBuilder
|
|
15
31
|
* new TransactionBuilder(client.rpc)
|
|
@@ -33,7 +49,7 @@ export declare class Action {
|
|
|
33
49
|
/**
|
|
34
50
|
* Executes the action directly.
|
|
35
51
|
*
|
|
36
|
-
* @returns
|
|
52
|
+
* @returns A PendingTransaction with the hash and .confirm() method
|
|
37
53
|
*/
|
|
38
|
-
execute(): Promise<
|
|
54
|
+
execute(): Promise<PendingTransaction>;
|
|
39
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentaproject/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@mentaproject/contracts": "^0.0.11",
|
|
38
38
|
"@mentaproject/core": "^0.7.3",
|
|
39
|
+
"@mentaproject/transactions": "^0.0.3",
|
|
39
40
|
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
40
41
|
"@shazow/whatsabi": "^0.21.1"
|
|
41
42
|
},
|
|
@@ -1,92 +1,97 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module TransactionManager
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { Transaction } from "../structures/Transaction";
|
|
4
|
+
import { GetTransactionParameters, Transaction as RawTransaction, SendTransactionParameters } from "@mentaproject/core/types";
|
|
5
|
+
import { Transaction as RichTransaction } from "../structures/Transaction";
|
|
6
|
+
import { MulticallTransaction } from "@mentaproject/transactions";
|
|
6
7
|
import { getTransaction, sendTransaction } from "@mentaproject/core/actions";
|
|
7
8
|
import { MentaClient } from "../structures";
|
|
8
9
|
import { JSONTransaction } from "../types";
|
|
9
10
|
import { parseBingints } from "../utils/bigint";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Manages blockchain transaction-related operations
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* Manages blockchain transaction-related operations.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Create a multicall transaction
|
|
18
|
+
* const pending = await client.transactions.create()
|
|
19
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
20
|
+
* .addCall(erc20.transfer(to, amount))
|
|
21
|
+
* .execute();
|
|
22
|
+
*
|
|
23
|
+
* const receipt = await pending.confirm();
|
|
24
|
+
*
|
|
25
|
+
* // Get a transaction by hash
|
|
26
|
+
* const tx = await client.transactions.fromHash(hash);
|
|
27
|
+
* console.log(tx.receipt, tx.block);
|
|
28
|
+
* ```
|
|
17
29
|
*/
|
|
18
30
|
export class TransactionManager {
|
|
19
|
-
|
|
20
|
-
* Creates an instance of `TransactionManager`.
|
|
21
|
-
* @constructor
|
|
22
|
-
* @param {MentaClient} client - The instance of MentaClient used to interact with the blockchain.
|
|
23
|
-
*/
|
|
24
|
-
constructor(public client: MentaClient) {};
|
|
31
|
+
constructor(public client: MentaClient) {}
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new MulticallTransaction for batching multiple calls.
|
|
35
|
+
*
|
|
36
|
+
* @returns A MulticallTransaction builder
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const pending = await client.transactions.create()
|
|
41
|
+
* .addCall(account.sendEth(parseEther("1")))
|
|
42
|
+
* .addCall(erc20.transfer(to, amount))
|
|
43
|
+
* .execute();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
create(): MulticallTransaction {
|
|
47
|
+
return new MulticallTransaction(this.client.rpc);
|
|
48
|
+
}
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves a rich transaction by its hash.
|
|
52
|
+
*
|
|
53
|
+
* @param hash - The transaction hash
|
|
54
|
+
* @returns A rich Transaction with receipt, block, etc.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const tx = await client.transactions.fromHash(hash);
|
|
59
|
+
* console.log(tx.from, tx.to, tx.value);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async fromHash(hash: `0x${string}`): Promise<RichTransaction> {
|
|
63
|
+
return this.get({ hash });
|
|
64
|
+
}
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves a transaction by its hash or block number and index.
|
|
68
|
+
*/
|
|
69
|
+
async get(params: GetTransactionParameters): Promise<RichTransaction> {
|
|
70
|
+
const data = await getTransaction(this.client.rpc, params);
|
|
71
|
+
return new RichTransaction(this.client, data);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parse a transaction object from a JSON converted transaction data object.
|
|
76
|
+
*/
|
|
77
|
+
parse<J extends JSONTransaction<0>>(data: J): RichTransaction {
|
|
78
|
+
const parsed = parseBingints(data);
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param {SendTransactionParameters} params - The parameters required to send the transaction,
|
|
67
|
-
* such as `to`, `value`, `data`, `gasLimit`, etc.
|
|
68
|
-
* @returns {Promise<Transaction>} A promise that resolves to a {@link Transaction} instance
|
|
69
|
-
* representing the sent transaction, including its hash and other details.
|
|
70
|
-
* @example
|
|
71
|
-
* import { MentaClient } from '@mentaproject/client';
|
|
72
|
-
* import { http } from '@mentaproject/core';
|
|
73
|
-
*
|
|
74
|
-
* // This example assumes you have an account with funds, which is available to the client.
|
|
75
|
-
* const client = new MentaClient({
|
|
76
|
-
* chain: 'mainnet',
|
|
77
|
-
* transport: http('http://rpcurlhere.com')
|
|
78
|
-
* });
|
|
79
|
-
*
|
|
80
|
-
* const transactionResult = await client.transactions.send({
|
|
81
|
-
* to: '0xRecipientAddress...', // Replace with a valid recipient address
|
|
82
|
-
* value: 1000000000000000000n, // 1 ETH in wei
|
|
83
|
-
* });
|
|
84
|
-
*
|
|
85
|
-
* console.log('Transaction sent with hash:', transactionResult.hash);
|
|
86
|
-
*/
|
|
87
|
-
async send(params: SendTransactionParameters): Promise<Transaction> {
|
|
88
|
-
const hash = await sendTransaction(this.client.rpc, params);
|
|
89
|
-
|
|
90
|
-
return await this.get({ hash });
|
|
80
|
+
const rawData = {
|
|
81
|
+
...parsed,
|
|
82
|
+
from: parsed.from.address,
|
|
83
|
+
to: parsed.to ? parsed.to.address : null,
|
|
91
84
|
};
|
|
92
|
-
|
|
85
|
+
|
|
86
|
+
return new RichTransaction(this.client, rawData as RawTransaction);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Sends a transaction to the blockchain network.
|
|
91
|
+
* @deprecated Use client.transactions.create() for new transactions
|
|
92
|
+
*/
|
|
93
|
+
async send(params: SendTransactionParameters): Promise<RichTransaction> {
|
|
94
|
+
const hash = await sendTransaction(this.client.rpc, params);
|
|
95
|
+
return await this.get({ hash });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
Hash,
|
|
12
12
|
onBlockRangeCallback,
|
|
13
13
|
} from "@mentaproject/core/types";
|
|
14
|
-
import { Transaction } from "./Transaction";
|
|
15
|
-
import {
|
|
14
|
+
import { Transaction as RichTransaction } from "./Transaction";
|
|
15
|
+
import { Transaction } from "@mentaproject/transactions";
|
|
16
16
|
import { toHex } from "@mentaproject/core/utils";
|
|
17
17
|
import {
|
|
18
18
|
AccountData,
|
|
@@ -54,22 +54,23 @@ export class Account implements AccountData {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Creates
|
|
57
|
+
* Creates a Transaction to send ETH to this account.
|
|
58
58
|
*
|
|
59
59
|
* @param amount The amount of ETH to send, in wei.
|
|
60
|
-
* @returns
|
|
60
|
+
* @returns A Transaction with .call(), .simulate(), and .execute() methods.
|
|
61
61
|
*
|
|
62
62
|
* @example
|
|
63
63
|
* ```ts
|
|
64
64
|
* // Direct execution
|
|
65
|
-
* await account.sendEth(parseEther("1")).execute();
|
|
65
|
+
* const pending = await account.sendEth(parseEther("1")).execute();
|
|
66
|
+
* const receipt = await pending.confirm();
|
|
66
67
|
*
|
|
67
|
-
* // Batch with
|
|
68
|
-
*
|
|
68
|
+
* // Batch with MulticallTransaction
|
|
69
|
+
* multicall.addCall(account.sendEth(parseEther("1")));
|
|
69
70
|
* ```
|
|
70
71
|
*/
|
|
71
|
-
sendEth(amount: bigint):
|
|
72
|
-
return new
|
|
72
|
+
sendEth(amount: bigint): Transaction {
|
|
73
|
+
return new Transaction(this.client.rpc, {
|
|
73
74
|
to: this.address,
|
|
74
75
|
value: amount,
|
|
75
76
|
});
|
|
@@ -86,7 +87,7 @@ export class Account implements AccountData {
|
|
|
86
87
|
async transactions(
|
|
87
88
|
params: GetTransactionsParams,
|
|
88
89
|
forceFetch = false,
|
|
89
|
-
): Promise<
|
|
90
|
+
): Promise<RichTransaction[]> {
|
|
90
91
|
if (!this.persistenceManager || forceFetch) {
|
|
91
92
|
const hashes = await this._fetchTransactions(params);
|
|
92
93
|
const transactions = await Promise.all(
|
package/src/structures/index.ts
CHANGED
package/src/structures/Action.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Call, Hex } from "@mentaproject/core";
|
|
2
|
-
import { MentaAccountClient } from "@mentaproject/core/types";
|
|
3
|
-
import { simulateCalls } from "@mentaproject/core/actions";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generic action object that wraps a single call.
|
|
7
|
-
*
|
|
8
|
-
* Provides `.call()` for batching with TransactionBuilder
|
|
9
|
-
* and `.execute()` for direct execution.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Direct execution
|
|
14
|
-
* await account.sendEth(parseEther("1")).execute();
|
|
15
|
-
*
|
|
16
|
-
* // Batching with TransactionBuilder
|
|
17
|
-
* new TransactionBuilder(client.rpc)
|
|
18
|
-
* .addCall(account.sendEth(parseEther("1")))
|
|
19
|
-
* .addCall(token.transfer(to, amount))
|
|
20
|
-
* .execute();
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export class Action {
|
|
24
|
-
constructor(
|
|
25
|
-
private client: MentaAccountClient,
|
|
26
|
-
private _call: Call,
|
|
27
|
-
) {}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Returns the Call object for use with TransactionBuilder.
|
|
31
|
-
*/
|
|
32
|
-
call(): Call {
|
|
33
|
-
return this._call;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Simulates the action without executing.
|
|
38
|
-
*/
|
|
39
|
-
async simulate() {
|
|
40
|
-
return simulateCalls(this.client, { calls: [this._call] });
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Executes the action directly.
|
|
45
|
-
*
|
|
46
|
-
* @returns Transaction hash
|
|
47
|
-
*/
|
|
48
|
-
async execute(): Promise<Hex> {
|
|
49
|
-
return this.client.sendTransaction(this._call as any);
|
|
50
|
-
}
|
|
51
|
-
}
|