Skip to content

Commit 0fc9da1

Browse files
committed
Add basic accounts-api package to fetch transactions
This PR demonstrates what a data service class to hit the Accounts API would look like. It's designed to fetch the list of transactions in the extension. For more, see: <MetaMask/metamask-extension#41522> Please note this PR is only intended for demo purposes. For a living example of a data service, including tests, please see: <https://github.com/MetaMask/core/blob/main/packages/sample-controllers/src/sample-gas-prices-service/sample-gas-prices-service.ts>
1 parent 109b22e commit 0fc9da1

16 files changed

Lines changed: 646 additions & 1 deletion

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Each package in this repository has its own README where you can find installati
2121
<!-- start package list -->
2222

2323
- [`@metamask/account-tree-controller`](packages/account-tree-controller)
24+
- [`@metamask/accounts-api`](packages/accounts-api)
2425
- [`@metamask/accounts-controller`](packages/accounts-controller)
2526
- [`@metamask/address-book-controller`](packages/address-book-controller)
2627
- [`@metamask/ai-controllers`](packages/ai-controllers)
@@ -107,6 +108,7 @@ Each package in this repository has its own README where you can find installati
107108
graph LR;
108109
linkStyle default opacity:0.5
109110
account_tree_controller(["@metamask/account-tree-controller"]);
111+
accounts_api(["@metamask/accounts-api"]);
110112
accounts_controller(["@metamask/accounts-controller"]);
111113
address_book_controller(["@metamask/address-book-controller"]);
112114
ai_controllers(["@metamask/ai-controllers"]);
@@ -189,6 +191,9 @@ linkStyle default opacity:0.5
189191
account_tree_controller --> messenger;
190192
account_tree_controller --> multichain_account_service;
191193
account_tree_controller --> profile_sync_controller;
194+
accounts_api --> base_data_service;
195+
accounts_api --> controller_utils;
196+
accounts_api --> messenger;
192197
accounts_controller --> base_controller;
193198
accounts_controller --> keyring_controller;
194199
accounts_controller --> messenger;

packages/accounts-api/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
[Unreleased]: https://github.com/MetaMask/core/

packages/accounts-api/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MIT License
2+
3+
Copyright (c) 2026 MetaMask
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

packages/accounts-api/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# `@metamask/accounts-api`
2+
3+
Wraps the Accounts API.
4+
5+
## Installation
6+
7+
`yarn add @metamask/accounts-api`
8+
9+
or
10+
11+
`npm install @metamask/accounts-api`
12+
13+
## Contributing
14+
15+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
const merge = require('deepmerge');
7+
const path = require('path');
8+
9+
const baseConfig = require('../../jest.config.packages');
10+
11+
const displayName = path.basename(__dirname);
12+
13+
module.exports = merge(baseConfig, {
14+
// The display name when running multiple projects
15+
displayName,
16+
17+
// An object that configures minimum threshold enforcement for coverage results
18+
coverageThreshold: {
19+
global: {
20+
branches: 100,
21+
functions: 100,
22+
lines: 100,
23+
statements: 100,
24+
},
25+
},
26+
});

packages/accounts-api/package.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "@metamask/accounts-api",
3+
"version": "0.0.0",
4+
"description": "Wraps the Accounts API",
5+
"keywords": [
6+
"MetaMask",
7+
"Ethereum"
8+
],
9+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/accounts-api#readme",
10+
"bugs": {
11+
"url": "https://github.com/MetaMask/core/issues"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/MetaMask/core.git"
16+
},
17+
"license": "MIT",
18+
"sideEffects": false,
19+
"exports": {
20+
".": {
21+
"import": {
22+
"types": "./dist/index.d.mts",
23+
"default": "./dist/index.mjs"
24+
},
25+
"require": {
26+
"types": "./dist/index.d.cts",
27+
"default": "./dist/index.cjs"
28+
}
29+
},
30+
"./package.json": "./package.json"
31+
},
32+
"main": "./dist/index.cjs",
33+
"types": "./dist/index.d.cts",
34+
"files": [
35+
"dist/"
36+
],
37+
"scripts": {
38+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
39+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
40+
"build:docs": "typedoc",
41+
"changelog:update": "../../scripts/update-changelog.sh @metamask/accounts-api",
42+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/accounts-api",
43+
"messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --check",
44+
"messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --generate",
45+
"since-latest-release": "../../scripts/since-latest-release.sh",
46+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
47+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
48+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
49+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
50+
},
51+
"dependencies": {
52+
"@metamask/base-data-service": "^0.1.1",
53+
"@metamask/controller-utils": "^11.20.0",
54+
"@metamask/messenger": "^1.1.1",
55+
"@metamask/superstruct": "^3.1.0",
56+
"@metamask/utils": "^11.9.0",
57+
"@tanstack/query-core": "^4.43.0"
58+
},
59+
"devDependencies": {
60+
"@metamask/auto-changelog": "^3.4.4",
61+
"@ts-bridge/cli": "^0.6.4",
62+
"@types/jest": "^29.5.14",
63+
"deepmerge": "^4.2.2",
64+
"jest": "^29.7.0",
65+
"ts-jest": "^29.2.5",
66+
"tsx": "^4.20.5",
67+
"typedoc": "^0.25.13",
68+
"typedoc-plugin-missing-exports": "^2.0.0",
69+
"typescript": "~5.3.3"
70+
},
71+
"engines": {
72+
"node": "^18.18 || >=20"
73+
},
74+
"publishConfig": {
75+
"access": "public",
76+
"registry": "https://registry.npmjs.org/"
77+
}
78+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* This file is auto generated.
3+
* Do not edit manually.
4+
*/
5+
6+
import type { AccountsApiService } from './accounts-api-service';
7+
8+
/**
9+
* Get multi-account transactions (v4 endpoint).
10+
*
11+
* @param params - Essential params
12+
* @param params.accountAddresses - Array of CAIP-10 account addresses.
13+
* @param options - Query filter options.
14+
* @param options.networks - Comma-separated CAIP-2 network IDs.
15+
* @param options.startTimestamp - Start timestamp (epoch) from which to return results.
16+
* @param options.endTimestamp - End timestamp (epoch) for which to return results.
17+
* @param options.limit - Maximum number of transactions to request (default 50).
18+
* @param options.after - JWT containing the endCursor for the query.
19+
* @param options.before - JWT containing the startCursor for the query.
20+
* @param options.sortDirection - Sort direction (ASC/DESC).
21+
* @param options.includeLogs - Whether to include logs.
22+
* @param options.includeTxMetadata - Whether to include transaction metadata.
23+
* @param options.maxLogsPerTx - Maximum number of logs per transaction.
24+
* @param options.lang - Language for transaction category (default "en").
25+
* @param page - Pagination cursors.
26+
* @returns The multi-account transactions response.
27+
*/
28+
export type AccountsApiServiceFetchMultiAccountTransactionsV4Action = {
29+
type: `AccountsApiService:fetchMultiAccountTransactionsV4`;
30+
handler: AccountsApiService['fetchMultiAccountTransactionsV4'];
31+
};
32+
33+
/**
34+
* Union of all AccountsApiService action types.
35+
*/
36+
export type AccountsApiServiceMethodActions =
37+
AccountsApiServiceFetchMultiAccountTransactionsV4Action;

0 commit comments

Comments
 (0)