Documentation Index
Fetch the complete documentation index at: https://docs.gelato.cloud/llms.txt
Use this file to discover all available pages before exploring further.
Gas estimation helps avoid failed transactions and provides transparency into expected costs.
Implementations
Gelato Gasless SDK
With 7702 Smart Account
Relay API Endpoints
Initialize Relayer Client
import { createGelatoEvmRelayerClient } from '@gelatocloud/gasless';
import { createPublicClient, encodeFunctionData, formatUnits, http } from 'viem';
import { baseSepolia } from 'viem/chains';
const relayer = createGelatoEvmRelayerClient({
apiKey: process.env.GELATO_API_KEY,
testnet: true
});
const publicClient = createPublicClient({
chain: baseSepolia,
transport: http()
});
Estimate Gas
const data = encodeFunctionData({
abi: [{ type: 'function', name: 'increment', inputs: [], outputs: [] }],
functionName: 'increment'
});
const gasEstimate = await publicClient.estimateGas({
to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
data
});
console.log('Estimated gas:', gasEstimate.toString());
Get Fee Data
Get current gas price:const feeData = await relayer.getFeeData({
chainId: baseSepolia.id
});
console.log('Gas Price:', feeData.gasPrice.toString(), 'wei');
Create Smart Account
import {
createGelatoSmartAccountClient,
toGelatoSmartAccount,
} from "@gelatocloud/gasless";
import { createPublicClient, http, type Hex, formatEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";
const owner = privateKeyToAccount(process.env.PRIVATE_KEY as Hex);
const client = createPublicClient({
chain: baseSepolia,
transport: http(),
});
const account = toGelatoSmartAccount({
client,
owner,
});
const relayer = await createGelatoSmartAccountClient({
account,
apiKey: process.env.GELATO_API_KEY,
});
Get Fee Quote
const quote = await relayer.getFeeQuote({
calls: [
{
to: "0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De",
data: "0xd09de08a",
},
],
});
console.log(`Estimated fee: ${formatEther(quote.estimatedFee)} ETH`);
Estimate for Multiple Transactions
const quote = await relayer.getFeeQuote({
calls: [
{
to: "0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De",
data: "0xd09de08a",
},
{
to: "0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De",
data: "0xd09de08a",
},
],
});
console.log(`Estimated fee: ${formatEther(quote.estimatedFee)} ETH`);
Pass the API key in the X-API-Key header.Estimate Gas (Chain RPC)
const response = await fetch('https://sepolia.base.org', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'eth_estimateGas',
params: [{
to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
data: '0xd09de08a'
}]
})
});
const result = await response.json();
const gasEstimate = parseInt(result.result, 16);
Get Fee Data
const response = await fetch('https://api.gelato.cloud/rpc', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.GELATO_API_KEY
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'relayer_getFeeData',
params: {
chainId: '84532'
}
})
});
const data = await response.json();
console.log('Gas Price:', data.result.gasPrice, 'wei');
Additional Resources