Fee Delegation Setup
Fee delegation allows your dApp to sponsor transaction fees for users, removing the barrier of requiring VTHO tokens.
What is Fee Delegation?
Fee delegation is a VeChain feature that enables applications to pay transaction fees on behalf of users. This creates a seamless user experience, especially for:
New users without VTHO tokens
Social login users (email, Google, etc.)
Improving overall user onboarding
Configuration
Add fee delegation to your VeChainKitProvider:
<VeChainKitProvider
feeDelegation={{
delegatorUrl: "YOUR_FEE_DELEGATION_URL",
delegateAllTransactions: true, // or false for social login only
}}
>
{children}
</VeChainKitProvider>Configuration Options
delegatorUrl: The endpoint URL for your fee delegation servicedelegateAllTransactions:true: Sponsor all transactions (wallet and social users)false: Sponsor only social login transactions (mandatory)
Setup Options
You have two options for setting up fee delegation:
Option 1: Create your own backend service
Option 2: Use existing free tools
Create Your Own Service
Deploy a custom fee delegation service as a microservice or backend endpoint.
Example Implementation (Cloudflare Worker)
Environment Variables
Security Considerations
Never expose your mnemonic: Store it securely in environment variables
Implement request validation: Check origin, transaction limits, etc.
Add rate limiting: Prevent abuse of your delegation service
Monitor usage: Track delegation requests and VTHO consumption
Use VeChain.Energy
VeChain.Energy provides a managed fee delegation service.
Setup Steps
For a detailed walkthrough, see the VeChain.Energy Fee Delegation Tutorial.
Configure Fee Delegation
Navigate to:
Your Project → Fee Delegation → ConfigurationsAdd the VeChain Kit smart contract address:
Mainnet:
0xD7B96cAC488fEE053daAf8dF74f306bBc237D3f5Testnet:
0x7C5114ef27a721Df187b32e4eD983BaB813B81Cb
Get Your Delegation URL
Your delegation URL will be:
https://sponsor-testnet.vechain.energy/by/YOUR_PROJECT_ID
Configure Your Provider
Smart Contract for Custom Rules
For advanced delegation rules, deploy a smart contract:
Monitoring and Alerts
For VeChain.Energy
Enable email notifications for low VTHO balance
Set up alerts in your project dashboard
Monitor usage statistics regularly
For Custom Solutions
Implement monitoring for:
VTHO balance of delegation wallet
Number of delegated transactions
Failed delegation attempts
Unusual activity patterns
Testing Fee Delegation
Test with Social Login
Verify Delegation Headers. Check that your delegation service returns proper headers:
Troubleshooting
Common Issues
"Fee delegation failed" error
Check delegation URL is correct
Verify VTHO balance in delegation wallet
Ensure CORS headers are properly set
Social login users can't transact
Confirm
feeDelegationis configured in providerCheck delegation service is running
Verify smart contract address is whitelisted
High VTHO consumption
Implement transaction limits
Add user verification
Monitor for unusual patterns
Best Practices
Security First
Never expose private keys or mnemonics
Implement proper authentication
Add rate limiting
User Experience
Ensure sufficient VTHO balance
Provide clear error messages
Monitor service uptime
Cost Management
Set reasonable limits
Track usage per user
Implement fair use policies
Last updated
Was this helpful?
