Fee Grant Module (x/feegrant)
Thex/feegrant module allows one account (the granter) to pay transaction fees on behalf of another account (the grantee). This enables use cases like onboarding new users without requiring them to acquire gas tokens first, or allowing services to sponsor transactions for their users.
Overview
x/feegrant implements ADR 029 to provide a framework where accounts can grant fee allowances to other accounts. Fee allowances can be limited by spending caps, time periods, or specific message types.
Key Concepts
FeeAllowanceI Interface
All fee allowance types implement theFeeAllowanceI interface:
Grant Structure
Fee allowance grants are stored with a composite key:- Granter: The account paying the fees
- Grantee: The account whose fees are being paid
- Allowance: The specific fee allowance logic
Fee Allowance Types
BasicAllowance
Provides a simple spending limit and optional expiration:spend_limit: Maximum coins that can be spent (nil = unlimited)expiration: When the allowance expires (nil = never)
PeriodicAllowance
Provides a recurring spending limit that resets after each period:basic: Optional BasicAllowance for overall limitsperiod: Duration of each spending periodperiod_spend_limit: Maximum coins per periodperiod_can_spend: Remaining coins in current periodperiod_reset: When the next period starts
AllowedMsgAllowance
Restricts a fee allowance to specific message types:Message Handlers
MsgGrantAllowance
Create a new fee allowance grant:MsgRevokeAllowance
Revoke an existing fee allowance:Using Fee Allowances
Fee allowances are automatically checked in theDeductFeeDecorator ante handler:
Fee Allowance Pruning
Expired allowances are automatically removed inEndBlock:
Query Endpoints
Allowance
Query a specific fee allowance:Allowances
Query all allowances for a grantee:Gas Considerations
Filtered allowances (AllowedMsgAllowance) consume gas during validation:CLI Examples
Grant Basic Allowance
Grant Periodic Allowance
Use Fee Allowance
Revoke Allowance
Query Allowances
Use Cases
User Onboarding
Subscription Service
Enterprise API Access
Best Practices
- Set spending limits to prevent abuse of fee allowances
- Use AllowedMsgAllowance to restrict what actions can be performed
- Set expiration times to automatically revoke unused allowances
- Monitor usage through events to detect anomalies
- Use PeriodicAllowance for recurring payments or subscriptions
- Test fee deduction logic thoroughly in your application
Security Considerations
- Fee allowances give the grantee the ability to spend the granter’s tokens on fees
- Always set reasonable spending limits
- Monitor for unexpected fee usage patterns
- Revoke allowances when they’re no longer needed
- Be cautious with unlimited allowances (nil SpendLimit)
- Validate that grantee addresses are trusted before creating grants