estimateGas
Action for estimating the gas necessary to complete a transaction without submitting it to the network.
Import
import { estimateGas } from '@wagmi/core'
Usage
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Parameters
import { type EstimateGasParameters } from '@wagmi/core'
accessList
AccessList | undefined
The access list.
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
accessList: [{
address: '0x1',
storageKeys: ['0x1'],
}],
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
account
Address | Account | undefined
Account to use when estimating gas.
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
chainId
config['chains'][number]['id'] | undefined
Chain ID to target when estimating gas.
import { estimateGas } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
chainId: mainnet.id,
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
connector
Connector | undefined
Connector to estimate with. If no account
is provided, will use default account from connector.
import { getConnections, estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const connections = getConnections(config)
const result = await estimateGas(config, {
connector: connections[0]?.connector,
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
data
`0x${string}` | undefined
A contract hashed method call with encoded args.
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
gas
bigint | undefined
Gas provided for transaction execution.
import { estimateGas } from '@wagmi/core'
import { parseEther, parseGwei } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
gas: parseGwei('20'),
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
gasPrice
bigint | undefined
The price in wei to pay per gas. Only applies to Legacy Transactions.
import { estimateGas } from '@wagmi/core'
import { parseEther, parseGwei } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
gasPrice: parseGwei('20'),
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
maxFeePerGas
bigint | undefined
Total fee per gas in wei, inclusive of maxPriorityFeePerGas
. Only applies to EIP-1559 Transactions.
import { estimateGas } from '@wagmi/core'
import { parseEther, parseGwei } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
maxFeePerGas: parseGwei('20'),
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
maxPriorityFeePerGas
bigint | undefined
Max priority fee per gas in wei. Only applies to EIP-1559 Transactions.
import { estimateGas } from '@wagmi/core'
import { parseEther, parseGwei } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
maxFeePerGas: parseGwei('20'),
maxPriorityFeePerGas: parseGwei('2'),
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
nonce
number
Unique number identifying this transaction.
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
nonce: 123,
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
to
Address | undefined
The transaction recipient or contract address.
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
type
'legacy' | 'eip1559' | 'eip2930' | undefined
Optional transaction request type to narrow parameters.
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
type: 'eip1559',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
value
bigint | undefined
Value in wei sent with this transaction.
import { estimateGas } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'
const result = await estimateGas(config, {
to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
value: parseEther('0.01'),
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Return Type
import { type EstimateGasReturnType } from '@wagmi/core'
bigint
The gas estimate in wei.
Error
import { type EstimateGasErrorType } from '@wagmi/core'
TanStack Query
import {
type EstimateGasData,
type EstimateGasOptions,
type EstimateGasQueryFnData,
type EstimateGasQueryKey,
estimateGasQueryKey,
estimateGasQueryOptions,
} from '@wagmi/core/query'