Learn how to implement gas sponsorship on Cosmos networks using fee grants with Para
This guide demonstrates how to implement gas sponsorship on Cosmos networks using fee grants. Unlike EVM chains that use account abstraction for gasless transactions, Cosmos networks natively support gas sponsorship through fee grants, allowing a grantor address to pay for another account’s transaction fees.
Fee grants in Cosmos allow one account (grantor) to pay transaction fees for another account (grantee). This mechanism provides native gas sponsorship without requiring smart contracts or account abstraction.Key concepts:
Grantor: The account that pays for gas fees
Grantee: The account whose transactions are sponsored
Allowance: Defines spending limits and expiration for the grant
Only one fee grant is allowed per granter-grantee pair. Self-grants are not permitted.
Once a fee grant is established, the grantee can perform transactions with sponsored gas fees:
Copy
Ask AI
// Create a signer for the granteeconst granteeSigner = new ParaProtoSigner(granteeParaInstance, "cosmos");const granteeClient = await SigningStargateClient.connectWithSigner(rpcUrl, granteeSigner);// Send tokens with sponsored gasconst result = await granteeClient.sendTokens( granteeAddress, "cosmos1recipient...", [{ denom: "uatom", amount: "100000" }], // 0.1 ATOM { amount: [{ denom: "uatom", amount: "5000" }], gas: "200000", granter: granterAddress // This tells the network to use the fee grant });
// Query grants for a specific granteeconst grantsByGrantee = await fetch( `${restUrl}/cosmos/feegrant/v1beta1/allowances/${granteeAddress}`).then(res => res.json());// Query all grants by a specific granterconst grantsByGranter = await fetch( `${restUrl}/cosmos/feegrant/v1beta1/issued/${granterAddress}`).then(res => res.json());// Query a specific grantconst specificGrant = await fetch( `${restUrl}/cosmos/feegrant/v1beta1/allowance/${granterAddress}/${granteeAddress}`).then(res => res.json());
For production applications, use server-side controlled wallets as grantors while allowing users to authenticate client-side as grantees. This pattern uses Para’s pregenerated wallets to create an app-controlled grantor wallet.
Create and manage a grantor wallet on your server:
Copy
Ask AI
// server.tsimport { Para } from "@getpara/server-sdk@alpha";import { SigningStargateClient } from "@cosmjs/stargate";import { ParaProtoSigner } from "@getpara/cosmjs-adapter@alpha";const serverPara = new Para(process.env.PARA_API_KEY);// Create a pregen wallet for gas sponsorshipconst grantorWallet = await serverPara.createPregenWallet({ type: 'COSMOS', pregenId: { customId: "app-gas-sponsor-wallet" }});// Store the user share securelyconst userShare = await serverPara.getUserShare();// Store userShare in your secure database
Set appropriate spending limits based on expected transaction volume
Use expiration times to automatically clean up unused grants
Monitor grant usage to control costs and detect abuse
Consider using periodic allowances for regular users
Use allowed message allowances to restrict transaction types
Remember that creating and revoking grants also incur gas costs
Fee grants provide native gas sponsorship on Cosmos networks without requiring smart contracts, making them more efficient than EVM account abstraction solutions.
Assistant
Responses are generated using AI and may contain mistakes.