MetaMask / MetaMask/metamask-extension
[Bug]: Incorrect gas estimation for NFT transfers on peaq Network possibly due to a hardcoded 95,000 gas limit cap
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
**Describe the bug**
When attempting to send an NFT on our network (Peaq, ChainId 3338 - https://chainlist.org/chain/3338), MetaMask's gas estimation fails for contracts with slightly more complex transfer logic. The `eth_estimateGas` call from MetaMask seems to include a hardcoded gas limit of 95,000, which is too low for that specific NFT contract for example. This results in the "Continue" button in the send-flow being greyed out, preventing users from sending their NFT. If I switch back from NFT to a token and then back to the NFT the "Continue" button becomes available which is very weird. I can attempt to send the NFT now with the "Send" button but it fails.
The transaction only succeeds if the user manually edits the gas limit to a more realistic value (e.g., 150,000). Standard ERC-721 NFTs with lower gas requirements work correctly, as do direct RPC calls using curl without a gas cap specified.
**Expected behavior**
MetaMask should correctly estimate the gas required for the NFT transfer by calling eth_estimateGas without imposing a low, hardcoded upper limit. The gas estimation should reflect the actual cost returned by the node, even if it exceeds 95,000, allowing the user to send the transaction without manual intervention.
**Screenshots/Recordings**
Attached a video recording file of the issue in the send flow.
https://github.com/user-attachments/assets/5d85d3af-a0ec-4b11-ba56-f40fa3cf03d6
**Steps to reproduce**
- Connect MetaMask to our custom EVM network (Peaq, ChainId 3338 - https://chainlist.org/chain/3338)
- Attempt to send an ERC-721 NFT where the transferFrom function's execution cost is greater than 95,000 gas.
- Proceed to the confirmation screen in the send-flow.
- Observe that the gas estimation is too low and the transaction cannot be confirmed.
**Error messages or log output**
After investigating our node's RPC logs, we found that MetaMask is sending the following eth_estimateGas request:
```
{
"id": "8e5cd44c-1fdf-4d7f-ae6e-1f137de226b2",
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [
{
"from": "0x5d015569e3d3542b8022591d8ec009633e2b51f4",
"value": "0x0",
"gasPrice": "0x174876e800",
"data": "0x23b872dd...00001807",
"to": "0x2b6c871c6d8A427a62ca458Cb720C9199204828D",
"gas": "0x17318"
}
]
}
```
The key issue is the "gas": "0x17318" parameter, which is a hexadecimal value for 95,000. This value acts as an upper bound for our node's gas estimation logic (which uses a binary search). Since the actual required gas is ~130,000, the node's estimation process fails to find a valid value within this cap, leading to the error.
When we make the same eth_estimateGas call via curl without the "gas" parameter, our node correctly estimates the required gas:
```
{
"jsonrpc": "2.0",
"result": "0x1de62", // 122,466
"id": 1
}
```
**Detection stage**
In production (default)
**Version**
13.2.1
**Build type**
None
**Browser**
Chrome
**Operating system**
MacOS
**Additional context**
Is it somehow possible that there is a hardcoded 95,000 gas cap from the eth_estimateGas call for NFT transfers? We need our RPC node to perform an unbounded estimation and return the true required gas.
Additionally, we noticed that other networks facing gas fee issues ( https://github.com/MetaMask/metamask-extension/issues/31611) saw improvements after being added to MetaMask's Gas API. Would adding our network (Peaq, ChainId 3338) to your API endpoint help resolve this or provide more accurate fee data? Currently it returns an error: https://gas.api.cx.metamask.io/networks/3338/suggestedGasFees.
Thank you for your time and consideration.
**Severity**
- This is very important since most of our users use MetaMask as their main wallet
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the send flow's eth_estimateGas request and compare the logged payload with the curl request, focusing on the gas parameter. Confirm whether the 95,000-gas value is imposed by MetaMask and identify the relevant estimation behavior. Done means NFT transfers needing more than 95,000 gas can be estimated and proceed without manual gas-limit editing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100