viem icon indicating copy to clipboard operation
viem copied to clipboard

feat: Add support for linea_estimateGas

Open wantedsystem opened this issue 1 year ago • 5 comments

Linea, a layer 2 blockchain, supports the Ethereum EIP-1559 gas price model, known for making transaction fees more predictable. Unlike the base Ethereum layer, Linea aims to offer a more stable and cost-effective approach to handling transaction fees. For detailed information, you can visit Linea's Gas Fees Documentation.

To further enhance the efficiency of transaction fee calculations, Linea has introduced a new RPC method designed to provide the best gas price estimates. This new method is documented in detail here.

The introduction of this new RPC method necessitates changes in how web3 libraries calculate gas prices. Traditionally, these libraries used the eth_gasPrice method. Linea's update shifts this approach to utilize the newly introduced linea_estimateGas method.

Detailed summary

  • Added linea_estimateGas RPC method to calculate accurate gas price on Linea network
  • Updated linea and lineaTestnet definitions to override fee calculation using linea_estimateGas
  • Added lineaEstimateGas and lineaEstimateFeesPerGas actions to calculate gas and fees
  • Updated types and imports related to fee calculation on Linea network

PR-Codex overview

This PR focuses on adding modules for estimating gas fees and fees per gas on the Linea chain.

Detailed summary

  • Added modules for lineaEstimateGas and lineaEstimateFeesPerGas
  • Defined types for gas estimation and fee calculation
  • Updated linea and lineaSepolia chain definitions with fee calculation overrides

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

wantedsystem avatar Jul 23 '24 10:07 wantedsystem

⚠️ No Changeset found

Latest commit: a5c1675e66caccba2abcffb8765c18222cd2f139

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jul 23 '24 10:07 changeset-bot[bot]

@wantedsystem is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jul 23 '24 10:07 vercel[bot]

Attempting to test this end-to-end, but I am running into issues on Linea Sepolia that the method linea_estimateGas is not available:

$ curl -X POST https://rpc.sepolia.linea.build \
     -H "Content-Type: application/json" \
     -d '{"id": 1, "jsonrpc": "2.0", "method": "linea_estimateGas", "params": [{"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", "value": "0xde0b6b3a7640000"}]}'
     
> {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"the method linea_estimateGas does not exist/is not available"}}

What RPC URL can I use to test this end-to-end?

jxom avatar Jul 26 '24 01:07 jxom

Attempting to test this end-to-end, but I am running into issues on Linea Sepolia that the method linea_estimateGas is not available:

$ curl -X POST https://rpc.sepolia.linea.build \
     -H "Content-Type: application/json" \
     -d '{"id": 1, "jsonrpc": "2.0", "method": "linea_estimateGas", "params": [{"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", "value": "0xde0b6b3a7640000"}]}'
     
> {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"the method linea_estimateGas does not exist/is not available"}}

What RPC URL can I use to test this end-to-end?

Hey @jxom It will be available soon -i'll keep you posted

wantedsystem avatar Jul 26 '24 12:07 wantedsystem

Since there are a few outstanding comments, going to convert this to a draft.

tmm avatar Aug 06 '24 12:08 tmm

Attempting to test this end-to-end, but I am running into issues on Linea Sepolia that the method linea_estimateGas is not available:

$ curl -X POST https://rpc.sepolia.linea.build \
     -H "Content-Type: application/json" \
     -d '{"id": 1, "jsonrpc": "2.0", "method": "linea_estimateGas", "params": [{"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", "value": "0xde0b6b3a7640000"}]}'
     
> {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"the method linea_estimateGas does not exist/is not available"}}

What RPC URL can I use to test this end-to-end?

You can test now for Linea Mainnet

curl https://rpc.linea.build \
       -X POST \
       -H "Content-Type: application/json" \
       -d '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0x91ba6c8DE41deC8E4d4E1C858f00FaE1819990Ca","gas":"0x21000"}],"id": 53}'

And for Linea Sepolia :

curl https://rpc.sepolia.linea.build \
       -X POST \
       -H "Content-Type: application/json" \
       -d '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0x91ba6c8DE41deC8E4d4E1C858f00FaE1819990Ca","gas":"0x21000"}],"id": 53}'

wantedsystem avatar Aug 12 '24 15:08 wantedsystem

Attempting to test this end-to-end, but I am running into issues on Linea Sepolia that the method linea_estimateGas is not available:

$ curl -X POST https://rpc.sepolia.linea.build \
     -H "Content-Type: application/json" \
     -d '{"id": 1, "jsonrpc": "2.0", "method": "linea_estimateGas", "params": [{"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", "value": "0xde0b6b3a7640000"}]}'
     
> {"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"the method linea_estimateGas does not exist/is not available"}}

What RPC URL can I use to test this end-to-end?

You can test now for Linea Mainnet

curl https://rpc.linea.build \
       -X POST \
       -H "Content-Type: application/json" \
       -d '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0x91ba6c8DE41deC8E4d4E1C858f00FaE1819990Ca","gas":"0x21000"}],"id": 53}'

And for Linea Sepolia :

curl https://rpc.sepolia.linea.build \
       -X POST \
       -H "Content-Type: application/json" \
       -d '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0x91ba6c8DE41deC8E4d4E1C858f00FaE1819990Ca","gas":"0x21000"}],"id": 53}'

Hey @jxom you had the opportunity to test ?

wantedsystem avatar Aug 20 '24 15:08 wantedsystem

Superseded by https://github.com/wevm/viem/pull/2665

jxom avatar Aug 29 '24 00:08 jxom