eth_estimateUserOperationGas
Simulates the user operation and estimates the appropriate gas limits. Returns an error if the operation is unsuccessful. This method uses 80 credits from your daily balance.
You can use stateOverrides
to estimate the gas cost even if the sender has no funds.
However, if the operation is sent onchain when the sender has no balance, it will revert during
the call phase due to lack of funds.
Parameters
-
userOperation
: (object) - The user operation object containing the following fields:sender
: (string) - The address of the account making the operation.nonce
: (string) - The account nonce.factory
: (string) [optional] - The factory contract address that will deploy the smart account if it doesn't exist yet.factoryData
: (string) [optional] - The data passed to the factory contract to deploy the smart account.callData
: (string) - The data to pass to the sender during the main execution call.callGasLimit
: (string) - The amount of gas to allocate the main execution call.verificationGasLimit
: (string) - The amount of gas to allocate for the verification step.preVerificationGas
: (string) - The amount of gas to pay for to compensate the bundler for pre-verification execution andcalldata
.maxFeePerGas
: (string) - Maximum fee per gas, in wei, the sender is willing to pay per gas.maxPriorityFeePerGas
: (string) - Maximum fee, in wei, the sender is willing to pay per gas above the base fee.paymaster
: (string) [optional] - Address of paymaster sponsoring the transaction, ornull
if none.paymasterVerificationGasLimit
: (string) [optional] - The amount of gas to allocate for the verification step of the paymaster, ornull
if no paymaster.paymasterPostOpGasLimit
: (string) [optional] - The amount of gas to allocate for the post-operation step of the paymaster, ornull
if no paymaster.paymasterData
: (string) [optional] - The data to pass to the paymaster during the verification step, ornull
if no paymaster.signature
: (string) - The signature data. For gas estimation, this can be a dummy signature. For example,0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c
eip7702Auth
: (object) [optional] - The EIP-7702 authorization data. This can be a dummy authorization for estimations:address
: (string) - The contract address for the authorization.chainId
: (string) - The chain ID.nonce
: (string) - The nonce.r
: (string) - The r component of the signature.s
: (string) - The s component of the signature.v
: (string) - The v component of the signature.yParity
: (string) - The y-parity value.
-
entryPoint
: (string) - The entry point contract address (0x0000000071727De22E5E9d8BAf0edAc6f37da032
). -
stateOverrides
: (object) [optional] - State overrides to apply for the simulation:- Each key is an address.
- Each value is an object that can contain:
balance
: (string) [optional] - The balance to set for the address.nonce
: (string) [optional] - The nonce to set for the address.code
: (string) [optional] - The code to set for the address.state
: (object) [optional] - Complete state to set, where each key is a 32-byte hex storage slot and each value is a 32-byte hex value.stateDiff
: (object) [optional] - State differences to apply, where each key is a 32-byte hex storage slot and each value is a 32-byte hex value.
Returns
An object containing the estimated gas values for the user operation.
preVerificationGas
: (string) - The amount of gas to pay for to compensate the bundler for pre-verification execution andcalldata
.verificationGasLimit
: (string) - The amount of gas to allocate for the verification step.callGasLimit
: (string) - The amount of gas to allocate the main execution call.paymasterVerificationGasLimit
: (string) - The amount of gas to allocate for the verification step of the paymaster, ornull
if no paymaster.paymasterPostOpGasLimit
: (string) - The amount of gas to allocate for the post-operation step of the paymaster, ornull
if no paymaster.
Example
Replace <YOUR-API-KEY>
with an API key from your MetaMask Developer dashboard.
Request
- curl without an override
- curl with an override
curl https://mainnet.infura.io/v3/<YOUR-API-KEY> \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateUserOperationGas",
"params": [
{
"sender": "0x5a6b47F4131bf1feAFA56A05573314BcF44C9149",
"nonce": "0x845adb2c711129d4f3966735ed98a9f09fc4ce5700000000000000000000",
"factory": "0xd703aaE79538628d27099B8c4f621bE4CCd142d5",
"factoryData": "0xc5265d5d000000000000000000000000aac5d4240af87249b3f71bc8e4a2cae074a3e419",
"callData": "0xe9ae5c5300000000000000000000000000000000000000000000000000000000000000000000000000",
"callGasLimit": "0x0",
"verificationGasLimit": "0x0",
"preVerificationGas": "0x0",
"maxFeePerGas": "0x7a5cf70d5",
"maxPriorityFeePerGas": "0x3b9aca00",
"paymaster": null,
"paymasterVerificationGasLimit": null,
"paymasterPostOpGasLimit": null,
"paymasterData": null,
"signature": "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
},
"0x0000000071727De22E5E9d8BAf0edAc6f37da032"
],
"id": 1
}'
curl https://mainnet.infura.io/v3/<YOUR-API-KEY> \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateUserOperationGas",
"params": [
{
"sender": "0xa203fDb8bC335F86016F635b85389B62B189E417",
"nonce": "0x35bf2a054f92f3730b87582ef223c8d663f9eb01158154750000000000000000",
"factory": "0x",
"callData": "0xb61d27f6000000000000000000000000530fff22987e137e7c8d2adcc4c15eb45b4fa752",
"callGasLimit": "0x0",
"verificationGasLimit": "0x0",
"preVerificationGas": "0x0",
"maxPriorityFeePerGas": "0x12a05f200",
"maxFeePerGas": "0x5b08082fa",
"paymaster": null,
"paymasterVerificationGasLimit": null,
"paymasterPostOpGasLimit": null,
"paymasterData": null,
"signature": "0xa6cc6589c8bd561cfd68d7b6b0757ef6f208e7438782939938498eee7d703260137856c840c491b3d415956265e81bf5c2184a725be2abfc365f7536b6af525e1c"
},
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
{
"0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3": {
"balance": "0xde0b6b3a7640000"
},
"0xebe8efa441b9302a0d7eaecc277c09d20d684540": {
"stateDiff": {
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80": "0x21"
}
}
}
],
"id": 1
}'
Response
- JSON
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"preVerificationGas": "0xd3e3",
"verificationGasLimit": "0x60b01",
"callGasLimit": "0x13880",
"paymasterVerificationGasLimit": "0x0",
"paymasterPostOpGasLimit": "0x0"
}
}