Babel Fee Box Pattern (Token-Based Fee Conversion)
Use Babel boxes so users can pay network fees through supported token-to-ERG conversion paths
Problem
Users may hold tokens but no ERG. They need a supported token-to-ERG fee path before they can transact without pre-funding ERG.
Solution
Babel fee boxes allow third parties (arbitrageurs) to pay ERG fees in exchange for supported tokens where a viable conversion path exists. Users include a Babel box offering tokens for ERG, and anyone can fulfill it.
How It Works
- 1User creates a Babel fee box: offers X supported tokens for Y ERG
- 2User's main transaction references Babel box
- 3Arbitrageur sees opportunity: provides ERG, takes tokens
- 4Transaction executes with ERG fees paid by arbitrageur
- 5User's tokens are exchanged for the fee payment
- 6Miners receive ERG as normal - no protocol changes needed
Code Examples
These snippets are educational references. Before using them with real funds, pin the exact SDK/compiler versions, validate register encodings, add collection-size guards before indexing arrays, publish test vectors, and keep production deployment behind an explicit review/audit gate.
{
// 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.size > 0 &&
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.size > 0 &&
o.tokens(0)._1 == offeredTokenId &&
o.tokens(0)._2 >= offeredAmount
)
}
hasTokens && (fulfilled || cancelled)
}Babel fee box offers a supported token 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
Resources
Users pay in tokens at a premium over ERG. Arbitrageurs profit from the spread. No protocol-level changes needed.