Filecoin.GasEstimateMessageGas - Filecoin

This method fills in the unset gas fields of a message, estimating the gas limit, fee cap, and premium needed for timely inclusion. The message is returned with its gas fields populated.

Parameters

ParameterTypeRequiredDescription
messageobjectYesThe message to estimate gas for
sendSpecobjectNoOptional send specification, such as a max fee; null to omit
tipsetKeyarrayYesTipset key to estimate against; empty array for the chain head

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{"jsonrpc": "2.0", "method": "Filecoin.GasEstimateMessageGas", "params": [{"To": "f1ne72cbn6r55wea7ifjv4ypyti7t2df5dumsjhzq", "From": "f3ukhj6tpkgxjknu54opiaej2vrjz7nh7gzodkqlhpfphc6gxkogzmojv2cnlpgcuwkvnyhloctnc6lmlvceuq", "Value": "1000000000000000000", "Method": 0}, null, []], "id": "getblock.io"}'

example.js

javascriptconst response = await fetch('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        jsonrpc: '2.0',
        method: 'Filecoin.GasEstimateMessageGas',
        params: [{"To": "f1ne72cbn6r55wea7ifjv4ypyti7t2df5dumsjhzq", "From": "f3ukhj6tpkgxjknu54opiaej2vrjz7nh7gzodkqlhpfphc6gxkogzmojv2cnlpgcuwkvnyhloctnc6lmlvceuq", "Value": "1000000000000000000", "Method": 0}, null, []],
        id: 'getblock.io'
    })
});

const data = await response.json();
console.log(data.result);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'Filecoin.GasEstimateMessageGas',
        'params': [{"To": "f1ne72cbn6r55wea7ifjv4ypyti7t2df5dumsjhzq", "From": "f3ukhj6tpkgxjknu54opiaej2vrjz7nh7gzodkqlhpfphc6gxkogzmojv2cnlpgcuwkvnyhloctnc6lmlvceuq", "Value": "1000000000000000000", "Method": 0}, null, []],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "To": "f1ne72cbn6r55wea7ifjv4ypyti7t2df5dumsjhzq",
        "From": "f3ukhj6tpkgxjknu54opiaej2vrjz7nh7gzodkqlhpfphc6gxkogzmojv2cnlpgcuwkvnyhloctnc6lmlvceuq",
        "Value": "1000000000000000000",
        "GasLimit": 2200000,
        "GasFeeCap": "101520",
        "GasPremium": "100178",
        "Method": 0,
        "Nonce": 43
    }
}

Response Parameters

FieldTypeDescription
GasLimitintegerEstimated maximum gas units for the message
GasFeeCapstringEstimated maximum fee per gas unit, in attoFIL
GasPremiumstringEstimated priority fee per gas unit, in attoFIL
NonceintegerNonce assigned to the message

Use Cases

  • Fee Estimation: Populate gas fields before signing a message
  • Cost Preview: Show the estimated cost of a message
  • Inclusion Tuning: Set gas for timely block inclusion
  • Wallet Flows: Prepare a fully specified message for signing

Error Handling

Error CodeMessageDescription
-32602Invalid paramsA parameter is missing or has the wrong type or format
1Actor not foundThe address or actor does not exist in the requested tipset
-32603Internal errorThe node failed to process the request