Important: When using Gelato Bundler for
Sponsoring Transactions with Gas Tank, both maxFeePerGas and maxPriorityFeePerGas are set to 0. This
allows transaction fees to be accurately settled post-execution, rather than
upfront via the EntryPoint.Implementations
- Gelato Gasless SDK
- Viem
- Permissionless
- API Endpoints
Copy
Ask AI
npm install @gelatocloud/gasless viem
Create an API Key
Check out our How-To Guide for detailed instructions on generating an API key.
Create Smart Account
Copy
Ask AI
import { createGelatoBundlerClient, sponsored, toGelatoSmartAccount } from '@gelatocloud/gasless';
import { createPublicClient, http } from 'viem';
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";
const owner = privateKeyToAccount(process.env.PRIVATE_KEY);
const client = createPublicClient({
chain: baseSepolia,
transport: http(),
});
const account = await toGelatoSmartAccount({
client,
owner,
});
Create Bundler Client
Copy
Ask AI
const bundler = await createGelatoBundlerClient({
account,
apiKey: process.env.GELATO_API_KEY,
client,
payment: sponsored(),
pollingInterval: 100
});
Send UserOperation
Copy
Ask AI
const hash = await bundler.sendUserOperation({
calls: [
{
data: '0xd09de08a',
to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De'
}
]
});
console.log(`User operation hash: ${hash}`);
const { receipt } = await bundler.waitForUserOperationReceipt({ hash });
console.log(`Transaction hash: ${receipt.transactionHash}`);
Copy
Ask AI
npm install viem
Create an API Key
Check out our How-To Guide for detailed instructions on generating an API key.
Create Bundler Client
Use
https://api.gelato.cloud for mainnets, or https://api.t.gelato.cloud for testnets. Pass the API key in the X-API-Key header via fetchOptions.Copy
Ask AI
import { createPublicClient, http } from "viem";
import { createBundlerClient } from "viem/account-abstraction";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";
const owner = privateKeyToAccount(process.env.PRIVATE_KEY);
const publicClient = createPublicClient({
chain: baseSepolia,
transport: http(),
});
const bundlerClient = createBundlerClient({
client: publicClient,
transport: http(`https://api.gelato.cloud/rpc/84532?payment=sponsored`, {
fetchOptions: {
headers: {
'X-API-Key': process.env.GELATO_API_KEY
}
}
}),
});
Send UserOperation
To use Gas Tank sponsorship efficiently, set
maxFeePerGas and maxPriorityFeePerGas to 0n. This allows transaction fees to be settled after execution via Gelato Gas Tank.Copy
Ask AI
const hash = await bundlerClient.sendUserOperation({
account,
calls: [
{
data: '0xd09de08a',
to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
value: 0n,
}
],
maxFeePerGas: 0n,
maxPriorityFeePerGas: 0n,
});
console.log(`User operation hash: ${hash}`);
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
console.log(`Transaction hash: ${receipt.receipt.transactionHash}`);
Copy
Ask AI
npm install permissionless viem
Create an API Key
Check out our How-To Guide for detailed instructions on generating an API key.
Create Smart Account
Copy
Ask AI
import { createSmartAccountClient } from "permissionless";
import { createPublicClient, http } from "viem";
import { createBundlerClient, toSoladySmartAccount } from "viem/account-abstraction";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";
const owner = privateKeyToAccount(process.env.PRIVATE_KEY);
const client = createPublicClient({
chain: baseSepolia,
transport: http(),
});
const account = await toSoladySmartAccount({
client,
owner,
});
Create Smart Account Client
Use
https://api.gelato.cloud for mainnets, or https://api.t.gelato.cloud for testnets. Pass the API key in the X-API-Key header via fetchOptions.Copy
Ask AI
const smartClient = createSmartAccountClient({
account,
chain: baseSepolia,
bundlerTransport: http(`https://api.gelato.cloud/rpc/84532?payment=sponsored`, {
fetchOptions: {
headers: {
'X-API-Key': process.env.GELATO_API_KEY
}
}
}),
});
Send UserOperation
To use Gas Tank sponsorship efficiently, set
maxFeePerGas and maxPriorityFeePerGas to 0n. This allows transaction fees to be settled after execution via Gelato Gas Tank.Copy
Ask AI
const hash = await smartClient.sendUserOperation({
account,
calls: [
{
data: '0xd09de08a',
to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De',
value: 0n,
}
],
maxFeePerGas: 0n,
maxPriorityFeePerGas: 0n,
});
console.log(`User operation hash: ${hash}`);
const receipt = await smartClient.waitForUserOperationReceipt({ hash });
console.log(`Transaction hash: ${receipt.receipt.transactionHash}`);
Use
https://api.gelato.cloud for mainnets, or https://api.t.gelato.cloud for testnets. Pass the API key in the X-API-Key header.Create an API Key
Check out our How-To Guide for detailed instructions on generating an API key.
Send UserOperation
To use Gas Tank sponsorship, ensure your UserOperation includes
maxFeePerGas and maxPriorityFeePerGas set to "0x0":Copy
Ask AI
{
"sender": "0x...",
"nonce": "0x...",
"callData": "0x...",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
...
}
Copy
Ask AI
const response = await fetch(
`https://api.gelato.cloud/rpc/${chainId}?payment=sponsored`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.GELATO_API_KEY
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "eth_sendUserOperation",
params: [userOperation, entryPoint],
id: 1,
}),
}
);
const data = await response.json();
const userOpHash = data.result;
Estimate Gas (Optional)
Copy
Ask AI
const response = await fetch(
`https://api.gelato.cloud/rpc/${chainId}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.GELATO_API_KEY
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "eth_estimateUserOperationGas",
params: [userOperation, entryPoint],
id: 1,
}),
}
);
const data = await response.json();
const gasEstimate = data.result;
Get UserOperation Receipt
Copy
Ask AI
const response = await fetch(
`https://api.gelato.cloud/rpc/${chainId}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.GELATO_API_KEY
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "eth_getUserOperationReceipt",
params: [userOpHash],
id: 1,
}),
}
);
const data = await response.json();
const receipt = data.result;