Skip to main content

linea_estimateGas

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete and be published on Ethereum. The transaction will not be added to the blockchain.

For more information about estimating gas, and how this API formulates the transaction costs, see the Estimate transaction costs topic.

The priorityFeePerGas returned by this method includes the cost of submitting the transaction to Ethereum, which can vary based on the size of the calldata.

note

linea_estimateGas uses the same inputs as the standard eth_estimateGas, but returns the recommended gas limit, the base fee per gas, and the priority fee per gas. We recommend using linea_estimateGas for more accurate results.

Parameters

  • call: [required] Transaction call object:
    • from: [optional] 20 bytes - The address the transaction is sent from.
    • to: [optional] 20 bytes - The address the transaction is directed to.
    • gas: [optional] Hexadecimal value of the gas provided for the transaction execution. linea_estimateGas consumes zero gas, but this parameter may be needed by some executions.
    • gasPrice: [optional] Hexadecimal value of the gas price used for each paid gas.
    • maxPriorityFeePerGas: [optional] Maximum fee, in wei, the sender is willing to pay per gas above the base fee.
    • maxFeePerGas: [optional] Maximum total fee (base fee + priority fee), in wei, the sender is willing to pay per gas.
    • value: [optional] Hexadecimal value of the value sent with this transaction.
    • data: [optional] Hash of the method signature and encoded parameters. See the Ethereum contract ABI specification.
  • stateOverride: [optional] Object that contains the address-to-state mapping to override state values. Each entry specifies a state that will be temporarily overridden before executing the call:
    • balance: [optional] Hexadecimal of the temporary account balance for the call execution.
    • nonce: [optional] Hexadecimal of the temporary nonce value for the call execution.
    • code : [optional] Bytecode to inject into the account.
    • stateDiff: key:value pairs to override individual slots in the account storage.

Returns

Hexadecimal values representing the recommended gas limit, the base fee per gas, and the priority fee per gas.

Example

tip

You can also call the API using Infura's supported Linea endpoints.

Request

curl https://linea-mainnet.infura.io/v3/YOUR-API-KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0","method": "linea_estimateGas","params": [{"from": "0x971e727e956690b9957be6d51Ec16E73AcAC83A7","gas":"0x21000"}],"id": 53}'

Response

{
"jsonrpc": "2.0",
"id": 53,
"result": {
"baseFeePerGas": "0x7",
"gasLimit": "0xcf08",
"priorityFeePerGas": "0x43a82a4"
}
}

Where:

  • baseFeePerGas - Uses the Linea base fee which is set at 7 wei.
  • gasLimit - Uses the standard eth_estimateGas API calculation.
  • priorityFeePerGas - Calculates the fee required to prioritize a transaction by considering factors such as the compressed transaction size, layer 1 verification costs and capacity, gas price ratio between layer 1 and layer 2, the transaction's gas usage, the minimum gas price on layer 2, and a minimum margin (for error) for gas price estimation.
note

The result of the request returns hexadecimal equivalent integers of gas prices in wei. Convert the hexadecimal value into decimals to get the wei value. You can use any hexadecimal to decimal converter such as RapidTables.

Override state values

You can override an account with temporary state values before making the call. This allows you to make temporary state changes without affecting the actual blockchain state.

The following example estimates the cost for transferring an ERC-20 token for an account which does not have the required assets onchain.

The example sets a custom ETH balance for the sender (to cover gas costs) and modifies the account's balance within the ERC-20 contract's storage for the duration of the call.

curl https://linea-mainnet.infura.io/v3/<YOUR-API-KEY> \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc":"2.0",
"method":"linea_estimateGas",
"params":[
{
"from":"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73",
"to":"0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
"data":"0xa9059cbb000000000000000000000000627306090abaB3A6e1400e9345bC60c78a8BEf570000000000000000000000000000000000000000000000001bc16d674ec80000"
},
{
"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73": {
"balance": "0x16345785d8a0000"
},
"0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f": {
"stateDiff":{
"0x2d206e5210c119b1cbed144f517f1f1dfd586eed26793a233e6afc261f4cf97f":"0x0000000000000000000000000000000000000000000000001bc16d674ec80000"
}
}
}
],
"id":53
}'