Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove @metamask/ethjs package #29620

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

cryptodev-2s
Copy link
Contributor

@cryptodev-2s cryptodev-2s commented Jan 9, 2025

Description

This PR introduces the following changes:
• Removes the @metamask/ethjs package.
• Replaces the global variable global.eth with the existing global.ethereumProvider (an instance of StreamProvider from web3-stream-provider package).
• Updates all instances of getCode to use a manual sendAsync call for the eth_getCode method, as StreamProvider does not include getCode, unlike ethjs.
• Substitutes the use of ethjs contracts with Contract instances from the @ethersproject/contracts library.
• Removal of @metamask/ethjs-contract and @metamask/ethjs-query packages.

The purpose of this PR is to simplify and break down the process of replacing web3-stream-provider (issue), which uses the legacy sendAsync method and is not EIP-1193 compliant, with StreamProvider from @metamask/providers, which fully adheres to the EIP-1193 Specs.

Open in GitHub Codespaces

Related issues

Fixes: partially completes #28774

Manual testing steps

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

@cryptodev-2s cryptodev-2s self-assigned this Jan 9, 2025
@cryptodev-2s cryptodev-2s requested a review from a team as a code owner January 9, 2025 21:38
@cryptodev-2s cryptodev-2s marked this pull request as draft January 9, 2025 21:38
Copy link
Contributor

github-actions bot commented Jan 9, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@cryptodev-2s
Copy link
Contributor Author

@metamaskbot update-policies

Copy link

socket-security bot commented Jan 9, 2025

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/@metamask/[email protected], npm/@metamask/[email protected], npm/[email protected]

View full report↗︎

@cryptodev-2s cryptodev-2s changed the title chore: remove ethjs chore: remove @metamask/ethjs package Jan 9, 2025
@metamaskbot
Copy link
Collaborator

Policy update failed. You can review the logs or retry the policy update here

@cryptodev-2s
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@cryptodev-2s cryptodev-2s force-pushed the cryptodev2s/remove-ethsjs branch 2 times, most recently from 345f6b1 to 0f60b67 Compare January 10, 2025 14:05
@@ -405,19 +404,6 @@ export function getRoundedGasPrice(gasPriceEstimate) {
return getGasPriceInHexWei(gasPriceAsNumber);
}

export async function getERC20Balance(token, accountAddress) {
Copy link
Contributor Author

@cryptodev-2s cryptodev-2s Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as not in use

@@ -90,15 +89,6 @@ const mockStore = createMockStore([thunk]);
const mockAddress1 = '0xdafea492d9c6733ae3d56b7ed1adb60692c98123';
const mockNftAddress1 = 'f4831105676a5fc024684d056390b8bc529daf51c7';

jest.mock('./send', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed as getERC20Balance not in use and has been removed from helpers

@cryptodev-2s cryptodev-2s force-pushed the cryptodev2s/remove-ethsjs branch 2 times, most recently from 4b84fee to c54a5c9 Compare January 10, 2025 22:54
try {
const result = await token.symbol();
return result[0];
const code = await contract.provider.getCode(tokenAddress);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @metamask/ethjs library is more lenient and permits interactions with non-existent contracts. This is why token.symbol() previously worked and returned an empty string (""). Now that we’ve removed ethjs, we need to first verify if the contract exists before attempting such calls.

@cryptodev-2s cryptodev-2s marked this pull request as ready for review January 10, 2025 23:01
@cryptodev-2s cryptodev-2s requested review from a team as code owners January 10, 2025 23:01
@metamaskbot
Copy link
Collaborator

Builds ready [c54a5c9]
Page Load Metrics (1800 ± 90 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint32121731737374180
domContentLoaded15232138176417986
load15732162180018790
domInteractive258634136
backgroundConnect989322211
firstReactRender16102412612
getState54714147
initialActions00000
loadScripts11441565131913364
setupStore687182211
uiStartup176926462074257124
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: -177 Bytes (-0.00%)
  • ui: -5.55 KiB (-0.07%)
  • common: 342 Bytes (0.00%)

@mikesposito
Copy link
Member

There's this other ethjs-contract usage we can get rid of, which would allow to also remove is as a dependency from package.json:

import EthContract from '@metamask/ethjs-contract';

@cryptodev-2s
Copy link
Contributor Author

@metamaskbot update-policies

@cryptodev-2s cryptodev-2s force-pushed the cryptodev2s/remove-ethsjs branch from f43efd9 to 6b3c256 Compare January 13, 2025 10:57
@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@metamaskbot
Copy link
Collaborator

Builds ready [d6ec3e4]
Page Load Metrics (1680 ± 111 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint141024051689235113
domContentLoaded140223011644219105
load141123691680232111
domInteractive216632115
backgroundConnect974372210
firstReactRender1599392713
getState594212211
initialActions01000
loadScripts9761650122016579
setupStore65314147
uiStartup162827251950316152
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: -310 Bytes (-0.01%)
  • ui: -5.55 KiB (-0.07%)
  • common: 625 Bytes (0.01%)

Copy link
Member

@mikesposito mikesposito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why removing ethjs-* packages is a prerequisite for the provider work?

@cryptodev-2s
Copy link
Contributor Author

Just curious: why removing ethjs-* packages is a prerequisite for the provider work?

The removal of @metamask/ethjs is necessary as it is not EIP-1193 compliant. This is required for the following PR: https://github.com/MetaMask/metamask-extension/pull/29650/files#diff-5a9d964db9d7c2fe207e21470884b2710e54723e0c1e6e6f7fd264706604fd6cR14. This PR replaces web3-stream-provider with StreamProvider from @metamask/providers, which exclusively supports EIP-1193 compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants