Skip to content

Commit

Permalink
feat: support Etherscan API keys (#27611)
Browse files Browse the repository at this point in the history
## **Description**

Upgrade the `TransactionController` to:

- Support Etherscan API keys when polling for incoming transactions.
- Populate `submitHistory` to aid with debug and persist even when
resetting the account.

Also adds the `ETHERSCAN_API_KEY` environment variable.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27611?quickstart=1)

## **Related issues**

## **Manual testing steps**

1. Verify incoming transactions work on Mainnet and Sepolia with an API
key set.
2. Verify `submitHistory` is populated in state logs after creating
transactions and retrying, on both Infura and custom networks.

## **Screenshots/Recordings**

### **Before**

### **After**

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
matthewwalsh0 authored Oct 7, 2024
1 parent 4c3232c commit 60ae8cb
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .metamaskrc.dist
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ BLOCKAID_PUBLIC_KEY=
; Enable/disable why did you render debug tool: https://github.com/welldone-software/why-did-you-render
; This should NEVER be enabled in production since it slows down react
; ENABLE_WHY_DID_YOU_RENDER=false

; API key used in Etherscan requests to prevent rate limiting.
; Only applies to Mainnet and Sepolia.
; ETHERSCAN_API_KEY=
4 changes: 4 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,10 @@ export default class MetamaskController extends EventEmitter {
getCurrentChainId({ metamask: this.networkController.state })
],
incomingTransactions: {
etherscanApiKeysByChainId: {
[CHAIN_IDS.MAINNET]: process.env.ETHERSCAN_API_KEY,
[CHAIN_IDS.SEPOLIA]: process.env.ETHERSCAN_API_KEY,
},
includeTokenTransfers: false,
isEnabled: () =>
Boolean(
Expand Down
5 changes: 4 additions & 1 deletion builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ env:
- SECURITY_ALERTS_API_ENABLED: ''
# URL of security alerts API used to validate dApp requests
- SECURITY_ALERTS_API_URL: 'http://localhost:3000'
# API key to authenticate Etherscan requests to avoid rate limiting
- ETHERSCAN_API_KEY: ''

# Enables the notifications feature within the build:
# Enables the notifications feature within the build:
- NOTIFICATIONS: ''

- METAMASK_RAMP_API_CONTENT_BASE_URL: https://on-ramp-content.api.cx.metamask.io
Expand All @@ -291,6 +293,7 @@ env:
###

- EIP_4337_ENTRYPOINT: null

###
# Enable/disable why did you render debug tool: https://github.com/welldone-software/why-did-you-render
# This should NEVER be enabled in production since it slows down react
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
"@metamask/snaps-rpc-methods": "^11.1.1",
"@metamask/snaps-sdk": "^6.5.1",
"@metamask/snaps-utils": "^8.1.1",
"@metamask/transaction-controller": "^37.1.0",
"@metamask/transaction-controller": "^37.2.0",
"@metamask/user-operation-controller": "^13.0.0",
"@metamask/utils": "^9.1.0",
"@ngraveio/bc-ur": "^1.1.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
},
"TxController": {
"methodData": "object",
"submitHistory": "object",
"transactions": "object",
"lastFetchedBlockNumbers": "object",
"submitHistory": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"isSignedIn": "boolean",
"isProfileSyncingEnabled": null,
"isProfileSyncingUpdateLoading": "boolean",
"submitHistory": "object",
"subscriptionAccountsSeen": "object",
"isMetamaskNotificationsFeatureSeen": "boolean",
"isNotificationServicesEnabled": "boolean",
Expand Down
3 changes: 0 additions & 3 deletions ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ function setupStateHooks(store) {
// for more info)
state.version = global.platform.getVersion();
state.browser = window.navigator.userAgent;
state.completeTxList = await actions.getTransactions({
filterToCurrentNetwork: false,
});
return state;
};
window.stateHooks.getSentryAppState = function () {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6462,9 +6462,9 @@ __metadata:
languageName: node
linkType: hard

"@metamask/transaction-controller@npm:^37.1.0":
version: 37.1.0
resolution: "@metamask/transaction-controller@npm:37.1.0"
"@metamask/transaction-controller@npm:^37.2.0":
version: 37.2.0
resolution: "@metamask/transaction-controller@npm:37.2.0"
dependencies:
"@ethereumjs/common": "npm:^3.2.0"
"@ethereumjs/tx": "npm:^4.2.0"
Expand All @@ -6491,7 +6491,7 @@ __metadata:
"@metamask/approval-controller": ^7.0.0
"@metamask/gas-fee-controller": ^20.0.0
"@metamask/network-controller": ^21.0.0
checksum: 10/b265c73f3410660ca2021f091508d6dec5e6b9cce240e420f91dd87f48d846ccca68d23892860fabd32dba62551476a9a7476d240679d58a50c1eab4cd04ab82
checksum: 10/0850797efb2157de41eaec153d31f8f63d194d2290fa41a3d439a28f95a35436f47d56546b0fa64427294280476d11ab4a7ed6161a13ad6f8215a3bc052a41e2
languageName: node
linkType: hard

Expand Down Expand Up @@ -26103,7 +26103,7 @@ __metadata:
"@metamask/snaps-utils": "npm:^8.1.1"
"@metamask/test-bundler": "npm:^1.0.0"
"@metamask/test-dapp": "npm:^8.4.0"
"@metamask/transaction-controller": "npm:^37.1.0"
"@metamask/transaction-controller": "npm:^37.2.0"
"@metamask/user-operation-controller": "npm:^13.0.0"
"@metamask/utils": "npm:^9.1.0"
"@ngraveio/bc-ur": "npm:^1.1.12"
Expand Down

0 comments on commit 60ae8cb

Please sign in to comment.