Developer Fundamentals

2. Sponsoring Your Users

Enable Fee Delegation in a transaction to allow a third party to pay gas fees.

Prerequisites

Fee Delegation

Transaction fees can be a headache for new users. What if someone else could pay for them? 🎁

On VeChain, Fee Delegation allows you to pass the gas payment to another wallet or a web service. This is perfect for developers who want to eliminate the friction of transaction fees for their users.

On-chain vs off-chain works like...

a prepaid tab at a cafe. The user orders the drink (transaction), but the shop (sponsor) covers the cost.

To enable this, you just need to set a single flag to true when building your transaction body:

const tx = await thor.transactions.buildTransactionBody(
  clauses, 
  gas.totalGas,
  { isDelegated: true } // Fee delegation activated!
);
const tx = await thor.transactions.buildTransactionBody(
  clauses, 
  gas.totalGas,
  { isDelegated: true } // Fee delegation activated!
);
const tx = await thor.transactions.buildTransactionBody(
  clauses, 
  gas.totalGas,
  { isDelegated: true } // Fee delegation activated!
);

Nice! Then, you provide the gasPayerServiceUrl or a sponsor's private key during the signing process.

Now your users can interact with your dApp without ever needing to worry about VTHO. That’s how you build for mass adoption!.