Ergo-Native Features
Intermediate
2-4 hours

Babel Fee Box Pattern (Pay Fees in Any Token)

Use Babel boxes so users pay network fees in arbitrary tokens

Problem

Users hold tokens but no ERG. They can't transact because they can't pay network fees.

Solution

Babel fee boxes allow third parties (arbitrageurs) to pay ERG fees in exchange for tokens. Users include a Babel box offering tokens for ERG, and anyone can fulfill it.

How It Works

  1. 1User creates a Babel fee box: offers X tokens for Y ERG
  2. 2User's main transaction references Babel box
  3. 3Arbitrageur sees opportunity: provides ERG, takes tokens
  4. 4Transaction executes with ERG fees paid by arbitrageur
  5. 5User's tokens are exchanged for the fee payment
  6. 6Miners receive ERG as normal - no protocol changes needed

Code Examples

{
  // Babel Fee Box: offers tokens for ERG
  // R4: Token ID being offered
  // R5: Token amount offered
  // R6: ERG amount requested
  // R7: User's address (for any leftover)
  
  val offeredTokenId = SELF.R4[Coll[Byte]].get
  val offeredAmount = SELF.R5[Long].get
  val requestedErg = SELF.R6[Long].get
  val userAddress = SELF.R7[Coll[Byte]].get
  
  // Verify box has the offered tokens
  val hasTokens = SELF.tokens(0)._1 == offeredTokenId &&
                  SELF.tokens(0)._2 >= offeredAmount
  
  // Babel box can be consumed if:
  // 1. User receives the requested ERG, OR
  // 2. User cancels (returns tokens to self)
  
  val fulfilled = {
    // User receives ERG
    OUTPUTS.exists(o =>
      o.propositionBytes == userAddress &&
      o.value >= requestedErg
    )
  }
  
  val cancelled = {
    // User gets tokens back
    OUTPUTS.exists(o =>
      o.propositionBytes == userAddress &&
      o.tokens(0)._1 == offeredTokenId &&
      o.tokens(0)._2 >= offeredAmount
    )
  }
  
  hasTokens && (fulfilled || cancelled)
}

Babel fee box offers tokens in exchange for ERG. Anyone can fulfill by providing ERG, or the user can cancel.

Use Cases

  • Onboarding users with only tokens
  • Token-only wallets and dApps
  • Gasless transactions for end users
  • Improved UX for token transfers
  • Fee abstraction layer

Security Considerations

  • !Set reasonable exchange rates to attract arbitrageurs
  • !Consider slippage in volatile markets
  • !Babel boxes can be front-run - use appropriate rates
  • !Include cancellation option for users

Real-World Implementations

Nautilus Wallet

Babel fee support in wallet

Resources

Fee Considerations

Users pay in tokens at a premium over ERG. Arbitrageurs profit from the spread. No protocol-level changes needed.

Level Up Your ErgoScript Skills

Get notified about new patterns, tutorials, and developer resources.

Follow for daily updates