estimateUserOperationGas
Estimates the gas values for a User Operation to be executed successfully.
Usage
example.ts
import { nexusClient } from "./nexusClient"
import { parseEther } from "viem"
// Estimate gas for a user operation
const gas = await nexusClient.estimateUserOperationGas({
calls: [{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
}]
})
Returns
{
callGasLimit: bigint;
preVerificationGas: bigint;
verificationGasLimit: bigint;
paymasterVerificationGasLimit: bigint | undefined;
paymasterPostOpGasLimit: bigint | undefined;
}
The estimated gas values for the User Operation.
Parameters
calls
- Type:
{ data?: Hex, to: Address, value?: bigint }[]
- Required: Yes
The calls to execute in the User Operation.
const gas = await nexusClient.estimateUserOperationGas({
calls: [{
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1')
}]
})
Contract Calls
The calls
property also accepts Contract Calls using the abi
, functionName
, and args
properties:
const gas = await nexusClient.estimateUserOperationGas({
calls: [{
abi: wagmiAbi,
functionName: 'mint',
to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
}]
})
Optional Parameters
callGasLimit
bigint
: Amount of gas to allocate for the main execution callmaxFeePerGas
bigint
: Maximum fee per gas for User Operation executionmaxPriorityFeePerGas
bigint
: Maximum priority fee per gasnonce
bigint
: Nonce for the User OperationverificationGasLimit
bigint
: Gas to allocate for verificationpreVerificationGas
bigint
: Extra gas to pay the Bundler
Paymaster Configuration
You can configure a paymaster in several ways:
// Using a paymaster address
const gas = await nexusClient.estimateUserOperationGas({
calls: [{
to: '0x...',
value: parseEther('1')
}],
paymaster: '0x942fD5017c0F60575930D8574Eaca13BEcD6e1bB',
paymasterData: '0xdeadbeef'
})
// Using a paymaster client
const gas = await nexusClient.estimateUserOperationGas({
calls: [{
to: '0x...',
value: parseEther('1')
}],
paymaster: paymasterClient,
paymasterContext: {
policyId: 'abc123'
}
})