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 service

  • delegateAllTransactions:

    • 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

  1. Never expose your mnemonic: Store it securely in environment variables

  2. Implement request validation: Check origin, transaction limits, etc.

  3. Add rate limiting: Prevent abuse of your delegation service

  4. 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.

  1. Visit VeChain.Energy

  2. Configure Fee Delegation

    • Navigate to: Your Project → Fee Delegation → Configurations

    • Add the VeChain Kit smart contract address:

      • Mainnet: 0xD7B96cAC488fEE053daAf8dF74f306bBc237D3f5

      • Testnet: 0x7C5114ef27a721Df187b32e4eD983BaB813B81Cb

  3. Get Your Delegation URL

    • Your delegation URL will be: https://sponsor-testnet.vechain.energy/by/YOUR_PROJECT_ID

  4. 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

  1. Test with Social Login

  2. Verify Delegation Headers. Check that your delegation service returns proper headers:

Troubleshooting

Common Issues

  1. "Fee delegation failed" error

    • Check delegation URL is correct

    • Verify VTHO balance in delegation wallet

    • Ensure CORS headers are properly set

  2. Social login users can't transact

    • Confirm feeDelegation is configured in provider

    • Check delegation service is running

    • Verify smart contract address is whitelisted

  3. High VTHO consumption

    • Implement transaction limits

    • Add user verification

    • Monitor for unusual patterns

Best Practices

  1. Security First

    • Never expose private keys or mnemonics

    • Implement proper authentication

    • Add rate limiting

  2. User Experience

    • Ensure sufficient VTHO balance

    • Provide clear error messages

    • Monitor service uptime

  3. Cost Management

    • Set reasonable limits

    • Track usage per user

    • Implement fair use policies

Last updated

Was this helpful?