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

Custom Network Gas Limit Estimation #5164

Open
dlebee opened this issue Jan 16, 2025 · 1 comment
Open

Custom Network Gas Limit Estimation #5164

dlebee opened this issue Jan 16, 2025 · 1 comment
Assignees

Comments

@dlebee
Copy link

dlebee commented Jan 16, 2025

Dear MetaMask Team,

I noticed the function getGas:

async function getGas(
  request: UpdateGasRequest,
): Promise<[string, TransactionMeta['simulationFails']?, string?]> {
  const { isCustomNetwork, chainId, txMeta } = request;

  if (txMeta.txParams.gas) {
    log('Using value from request', txMeta.txParams.gas);
    return [txMeta.txParams.gas, undefined, txMeta.txParams.gas];
  }

  if (await requiresFixedGas(request)) {
    log('Using fixed value', FIXED_GAS);
    return [FIXED_GAS, undefined, FIXED_GAS];
  }

  const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(
    txMeta.txParams,
    request.ethQuery,
  );

  if (isCustomNetwork || simulationFails) {
    log(
      isCustomNetwork
        ? 'Using original estimate as custom network'
        : 'Using original fallback estimate as simulation failed',
    );
    return [estimatedGas, simulationFails, estimatedGas];
  }

  const bufferMultiplier =
    GAS_BUFFER_CHAIN_OVERRIDES[
      chainId as keyof typeof GAS_BUFFER_CHAIN_OVERRIDES
    ] ?? DEFAULT_GAS_MULTIPLIER;

  const bufferedGas = addGasBuffer(
    estimatedGas,
    blockGasLimit,
    bufferMultiplier,
  );

  return [bufferedGas, simulationFails, estimatedGas];
}

I appreciate the use of gas buffering in this function as it helps improve the chances of transaction acceptance. However, I noticed that when adding a custom network, there is currently no option to configure a gas buffer or even apply one to the gas limit. This creates challenges for platforms that integrate with MetaMask but don’t estimate gas or add a buffer before sending transactions to the extension. As a result, many integrations fail, leading to a suboptimal user experience.

I believe it would significantly enhance usability if MetaMask allowed users to configure gas buffering as part of the custom network setup. This could be either:

A toggle to enable gas buffering for a specific network in the network setup.
An option in the advanced network settings to apply a configurable buffer multiplier.

I understand that some networks already buffer gas during the estimateGas RPC call, and the behavior can vary between networks. However, enabling this feature at the user or network level would reduce the need for manual gas limit adjustments, saving users 2-3 extra clicks every time they edit the gas limit for transactions, also it can be disabled by default.

I hope you find this feedback constructive and consider introducing these options to further improve the user experience.

Thank you for your time and effort in building an amazing platform. I look forward to seeing how MetaMask continues to evolve!

@kevinnguyen17
Copy link

kevinnguyen17 commented Jan 16, 2025

As we are in the era of booming new chains, this capability is crucial for Metamask's adaptability to

  • Ensure Metamask can support diverse network behaviors, especially for the new networks or specialized network
  • Allow dynamic gas estimation based on smart contract operations to optimize buffering, as some functions require minimal buffering, making large gas reserves inefficient.

@bschorchit bschorchit self-assigned this Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants