@mentaproject/client 0.1.24 → 0.1.25
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/structures/Account.d.ts +1 -1
- package/dist/structures/Account.js +20 -19
- package/dist/structures/MentaClient.d.ts +5 -2
- package/dist/structures/MentaClient.js +24 -5
- package/dist/types/MentaClient.d.ts +10 -2
- package/dist/types/MentaClient.js +0 -2
- package/package.json +3 -3
- package/src/structures/Account.ts +235 -190
- package/src/structures/MentaClient.ts +124 -99
- package/src/types/MentaClient.ts +46 -34
- package/transactions.json +0 -1302
|
@@ -100,5 +100,5 @@ export declare class Account implements AccountData {
|
|
|
100
100
|
* @param params - The parameters for the block range exploration.
|
|
101
101
|
* @returns A Promise that resolves to an array of transaction hashes.
|
|
102
102
|
*/
|
|
103
|
-
protected _fetchTransactions({ fromBlock, toBlock, limit }: FetchTransactionParams): Promise<Hash[]>;
|
|
103
|
+
protected _fetchTransactions({ fromBlock, toBlock, limit, }: FetchTransactionParams): Promise<Hash[]>;
|
|
104
104
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fetchByBlockRange, getBalance, getBlockNumber, getCode, getTransaction, getTransactionCount, sendTransaction, traceFilter } from "@mentaproject/core/actions";
|
|
1
|
+
import { fetchByBlockRange, getBalance, getBlockNumber, getCode, getTransaction, getTransactionCount, sendTransaction, traceFilter, } from "@mentaproject/core/actions";
|
|
2
2
|
import { Transaction } from "./Transaction";
|
|
3
3
|
import { toHex } from "@mentaproject/core/utils";
|
|
4
4
|
import { getContractType } from "@mentaproject/contracts";
|
|
@@ -31,7 +31,6 @@ export class Account {
|
|
|
31
31
|
return false;
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
|
-
;
|
|
35
34
|
/**
|
|
36
35
|
* Retrieves the type of the contract if the account is a smart contract.
|
|
37
36
|
* @description This method first checks if the account is a contract using `isContract()`.
|
|
@@ -44,7 +43,6 @@ export class Account {
|
|
|
44
43
|
return undefined;
|
|
45
44
|
return await getContractType(this.client.rpc, this.address);
|
|
46
45
|
}
|
|
47
|
-
;
|
|
48
46
|
/**
|
|
49
47
|
* Sends a specified amount of native cryptocurrency (ETH) to this account.
|
|
50
48
|
* @description This method constructs and sends a transaction to transfer ETH to the account's address.
|
|
@@ -53,15 +51,16 @@ export class Account {
|
|
|
53
51
|
*/
|
|
54
52
|
async sendETH(amount) {
|
|
55
53
|
const hash = await sendTransaction(this.client.rpc, {
|
|
56
|
-
calls: [
|
|
54
|
+
calls: [
|
|
55
|
+
{
|
|
57
56
|
to: this.address,
|
|
58
57
|
value: amount,
|
|
59
|
-
}
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
60
|
});
|
|
61
61
|
const data = await getTransaction(this.client.rpc, { hash });
|
|
62
62
|
return new Transaction(this.client, data);
|
|
63
63
|
}
|
|
64
|
-
;
|
|
65
64
|
/**
|
|
66
65
|
* Retrieves the current native cryptocurrency (ETH) balance of the account.
|
|
67
66
|
* @description This method queries the blockchain to get the balance associated with the account's address.
|
|
@@ -72,7 +71,6 @@ export class Account {
|
|
|
72
71
|
address: this.address,
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
|
-
;
|
|
76
74
|
/**
|
|
77
75
|
* Retrieves the transaction count (nonce) for the account.
|
|
78
76
|
* @description The transaction count represents the number of transactions sent from this account,
|
|
@@ -80,7 +78,9 @@ export class Account {
|
|
|
80
78
|
* @returns {Promise<number>} A promise that resolves to the transaction count of the account.
|
|
81
79
|
*/
|
|
82
80
|
async transactionCount() {
|
|
83
|
-
return await getTransactionCount(this.client.rpc, {
|
|
81
|
+
return await getTransactionCount(this.client.rpc, {
|
|
82
|
+
address: this.address,
|
|
83
|
+
});
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Retrieves all transactions involving this account.
|
|
@@ -99,11 +99,11 @@ export class Account {
|
|
|
99
99
|
if (!this.persistenceManager || forceFetch) {
|
|
100
100
|
// If persistence is not configured, fetch directly from remote
|
|
101
101
|
const hashes = await this._fetchTransactions(params);
|
|
102
|
-
const transactions = await Promise.all(hashes.map(hash => this.client.transactions.get({ hash })));
|
|
102
|
+
const transactions = await Promise.all(hashes.map((hash) => this.client.transactions.get({ hash })));
|
|
103
103
|
return transactions;
|
|
104
104
|
}
|
|
105
105
|
const jsons = await this.persistenceManager.getTransactions(this.address, params);
|
|
106
|
-
return jsons.map(j => this.client.transactions.parse(j));
|
|
106
|
+
return jsons.map((j) => this.client.transactions.parse(j));
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Synchronizes the account's transactions with the remote data source using the configured `PersistenceManager`.
|
|
@@ -127,7 +127,7 @@ export class Account {
|
|
|
127
127
|
*/
|
|
128
128
|
async tokenTransactions(tokenAddress) {
|
|
129
129
|
if (!this.persistenceManager)
|
|
130
|
-
throw new Error(
|
|
130
|
+
throw new Error("The persistence module is not configured.");
|
|
131
131
|
return {};
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
@@ -146,7 +146,7 @@ export class Account {
|
|
|
146
146
|
ETHBalance: this.ETHBalance.bind(this),
|
|
147
147
|
transactionCount: this.transactionCount.bind(this),
|
|
148
148
|
},
|
|
149
|
-
depth
|
|
149
|
+
depth,
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
@@ -155,29 +155,30 @@ export class Account {
|
|
|
155
155
|
* @param params - The parameters for the block range exploration.
|
|
156
156
|
* @returns A Promise that resolves to an array of transaction hashes.
|
|
157
157
|
*/
|
|
158
|
-
async _fetchTransactions({ fromBlock, toBlock, limit = 50 }) {
|
|
158
|
+
async _fetchTransactions({ fromBlock, toBlock, limit = 50, }) {
|
|
159
159
|
const lastBlock = await getBlockNumber(this.client.rpc);
|
|
160
160
|
const onBlockRange = async ({ fromBlock, toBlock }, stop) => {
|
|
161
161
|
const outgoing = await traceFilter(this.client.rpc, {
|
|
162
162
|
fromBlock: toHex(fromBlock),
|
|
163
163
|
toBlock: toHex(toBlock),
|
|
164
|
-
fromAddress: this.address
|
|
164
|
+
fromAddress: this.address,
|
|
165
165
|
});
|
|
166
166
|
const incoming = await traceFilter(this.client.rpc, {
|
|
167
167
|
fromBlock: toHex(fromBlock),
|
|
168
168
|
toBlock: toHex(toBlock),
|
|
169
|
-
toAddress: this.address
|
|
169
|
+
toAddress: this.address,
|
|
170
170
|
});
|
|
171
|
-
const traces = outgoing
|
|
172
|
-
|
|
171
|
+
const traces = outgoing
|
|
172
|
+
.concat(incoming)
|
|
173
|
+
.sort((a, b) => a.blockNumber - b.blockNumber);
|
|
174
|
+
return traces.map((t) => t.transactionHash);
|
|
173
175
|
};
|
|
174
176
|
return await fetchByBlockRange({
|
|
175
177
|
toBlock: BigInt(toBlock !== undefined ? toBlock : 0),
|
|
176
178
|
fromBlock: BigInt(fromBlock !== undefined ? fromBlock : lastBlock),
|
|
177
179
|
direction: "backward",
|
|
178
180
|
itemLimit: limit,
|
|
179
|
-
onBlockRange
|
|
181
|
+
onBlockRange,
|
|
180
182
|
});
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
|
-
;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module MentaClient
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { MentaAccountClient } from "@mentaproject/core/types";
|
|
5
5
|
import { BlockManager } from "../managers/BlockManager";
|
|
6
6
|
import { TransactionManager } from "../managers/TransactionManager";
|
|
7
7
|
import { ContractManager } from "../managers/ContractManager";
|
|
@@ -17,11 +17,13 @@ import { ClientEvents, GetListenerCallback, MentaClientConfig } from "../types/M
|
|
|
17
17
|
* simplifying common operations.
|
|
18
18
|
*/
|
|
19
19
|
export declare class MentaClient {
|
|
20
|
+
protected params: MentaClientConfig;
|
|
21
|
+
protected _rpc?: MentaAccountClient;
|
|
20
22
|
/**
|
|
21
23
|
* The underlying RPC client used for blockchain interactions.
|
|
22
24
|
* @description This client is responsible for low-level communication with the RPC node.
|
|
23
25
|
*/
|
|
24
|
-
rpc:
|
|
26
|
+
get rpc(): MentaAccountClient;
|
|
25
27
|
/**
|
|
26
28
|
* Manager for block-related operations.
|
|
27
29
|
* @description Provides methods to query and interact with blockchain blocks.
|
|
@@ -85,6 +87,7 @@ export declare class MentaClient {
|
|
|
85
87
|
* });
|
|
86
88
|
*/
|
|
87
89
|
constructor(params: MentaClientConfig);
|
|
90
|
+
init(): Promise<void>;
|
|
88
91
|
/**
|
|
89
92
|
* Optional manager for persistence-related operations.
|
|
90
93
|
* @description This manager is initialized if a persistence adapter is provided in the client configuration,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createMentaAccount } from "@mentaproject/core/clients";
|
|
2
2
|
import { BlockManager } from "../managers/BlockManager";
|
|
3
3
|
import { TransactionManager } from "../managers/TransactionManager";
|
|
4
4
|
import { ContractManager } from "../managers/ContractManager";
|
|
5
5
|
import { AccountManager } from "../managers/AccountManager";
|
|
6
6
|
import { PersistenceManager } from "../managers/PersistenceManager";
|
|
7
|
-
import { ClientEvents } from "../types/MentaClient";
|
|
7
|
+
import { ClientEvents, } from "../types/MentaClient";
|
|
8
8
|
import { withCache } from "../utils/withCache";
|
|
9
|
+
import { createClient } from "@mentaproject/core";
|
|
9
10
|
/**
|
|
10
11
|
* The main client for interacting with the Menta API.
|
|
11
12
|
* It provides managers for blocks, transactions, contracts, and accounts.
|
|
@@ -15,6 +16,16 @@ import { withCache } from "../utils/withCache";
|
|
|
15
16
|
* simplifying common operations.
|
|
16
17
|
*/
|
|
17
18
|
export class MentaClient {
|
|
19
|
+
/**
|
|
20
|
+
* The underlying RPC client used for blockchain interactions.
|
|
21
|
+
* @description This client is responsible for low-level communication with the RPC node.
|
|
22
|
+
*/
|
|
23
|
+
get rpc() {
|
|
24
|
+
if (!this._rpc) {
|
|
25
|
+
throw new Error("RPC client not initialized");
|
|
26
|
+
}
|
|
27
|
+
return this._rpc;
|
|
28
|
+
}
|
|
18
29
|
/**
|
|
19
30
|
* Subscribes to a specific client event.
|
|
20
31
|
* @template TEvent The type of the event to listen for.
|
|
@@ -66,9 +77,7 @@ export class MentaClient {
|
|
|
66
77
|
* });
|
|
67
78
|
*/
|
|
68
79
|
constructor(params) {
|
|
69
|
-
this.
|
|
70
|
-
if (params.cache)
|
|
71
|
-
this.rpc = withCache(this.rpc, params.cache);
|
|
80
|
+
this.params = params;
|
|
72
81
|
this.blocks = new BlockManager(this);
|
|
73
82
|
this.transactions = new TransactionManager(this);
|
|
74
83
|
this.contracts = new ContractManager(this);
|
|
@@ -80,4 +89,14 @@ export class MentaClient {
|
|
|
80
89
|
this.accounts = new AccountManager(this);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
92
|
+
async init() {
|
|
93
|
+
let coreClient = createClient(this.params);
|
|
94
|
+
if (this.params.cache) {
|
|
95
|
+
coreClient = withCache(coreClient, this.params.cache);
|
|
96
|
+
}
|
|
97
|
+
this._rpc = await createMentaAccount(coreClient, {
|
|
98
|
+
signer: this.params.signer,
|
|
99
|
+
bundlerTransport: this.params.bundlerTransport,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
83
102
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module MentaClientTypes
|
|
3
3
|
*/
|
|
4
|
-
import { CoreClientConfig } from "@mentaproject/core/types";
|
|
4
|
+
import { CoreClientConfig, PasskeySigner, Transport } from "@mentaproject/core/types";
|
|
5
5
|
import { ICache } from "./Cache";
|
|
6
6
|
import { watchBlockNumber, watchBlocks } from "@mentaproject/core/actions";
|
|
7
7
|
import { IPersistenceAdapter } from "./PersistenceAdapter";
|
|
@@ -33,6 +33,14 @@ export interface MentaClientConfig extends CoreClientConfig {
|
|
|
33
33
|
* If provided, the client will use this adapter to persist and retrieve data.
|
|
34
34
|
*/
|
|
35
35
|
persistenceAdapter?: IPersistenceAdapter;
|
|
36
|
+
/**
|
|
37
|
+
* Bundler transport used for userOperations
|
|
38
|
+
*/
|
|
39
|
+
bundlerTransport: Transport;
|
|
40
|
+
/**
|
|
41
|
+
* Passkey compatible signer used for signing user operations
|
|
42
|
+
*/
|
|
43
|
+
signer: PasskeySigner;
|
|
36
44
|
}
|
|
37
45
|
/**
|
|
38
46
|
* Defines the available client events and their corresponding watch functions.
|
|
@@ -55,6 +63,6 @@ export declare const ClientEvents: {
|
|
|
55
63
|
* This type dynamically determines the expected callback signature for a specific client event.
|
|
56
64
|
* @template TEvent The name of the event (e.g., 'block' or 'blockNumber') for which to get the listener callback type.
|
|
57
65
|
*/
|
|
58
|
-
export type GetListenerCallback<TEvent extends keyof typeof ClientEvents> = Parameters<typeof ClientEvents[TEvent]>[1] extends infer P ? P extends {
|
|
66
|
+
export type GetListenerCallback<TEvent extends keyof typeof ClientEvents> = Parameters<(typeof ClientEvents)[TEvent]>[1] extends infer P ? P extends {
|
|
59
67
|
[K in `on${Capitalize<TEvent>}`]: infer TCallback;
|
|
60
68
|
} ? TCallback : never : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentaproject/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"author": "@mentaproject",
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mentaproject/contracts": "^0.0.
|
|
35
|
-
"@mentaproject/core": "^0.5.
|
|
34
|
+
"@mentaproject/contracts": "^0.0.11",
|
|
35
|
+
"@mentaproject/core": "^0.5.13",
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
37
37
|
"@shazow/whatsabi": "^0.21.1"
|
|
38
38
|
},
|