IFeeCurrency interface and being added to the on-chain allowlist through governance. This guide explains the interface requirements and walks through an example implementation.
For background on how fee abstraction works, see the Overview.
The IFeeCurrency Interface
Fee currencies must implement the IFeeCurrency interface, which extends ERC20 with two additional functions used by the Celo blockchain to debit and credit gas fees. When a CIP-64 transaction is executed:- Before execution — the blockchain calls
debitGasFeesto reserve the maximum gas the transaction can spend - After execution — the blockchain calls
creditGasFeesto refund unused gas and distribute fees to the appropriate recipients
debitGasFees
- Must deduct
valuefromfrom’s balance - Must revert if
msg.senderis notaddress(0)(only the VM may call this)
creditGasFees
There are two versions ofcreditGasFees. Both should be implemented for compatibility.
New signature (used once all fee currencies have migrated):
- Must credit each
recipientthe correspondingamount - Must revert if
msg.senderis notaddress(0) - Must revert if
recipientsandamountshave different lengths
_gatewayFeeRecipientand_gatewayFeeAmountare deprecated and will always be zero- Must revert if
msg.senderis notaddress(0)
Example Implementation
The following example from celo-org/fee-currency-example shows a minimal fee currency token using OpenZeppelin’s ERC20 with burn/mint mechanics for gas fee handling:_burn in debitGasFees and _mint in creditGasFees to handle the gas fee lifecycle. The onlyVm modifier ensures only the blockchain itself (via address(0)) can call these functions.
Testing
Use Foundry to test your fee currency implementation. The fee-currency-example repository includes a test suite you can use as a starting point:debitGasFeescorrectly reduces the sender’s balancedebitGasFeesreverts when called by any address other thanaddress(0)- Both
creditGasFeessignatures correctly credit all recipients creditGasFeesreverts when called by any address other thanaddress(0)- The total debited amount equals the total credited amount across a transaction lifecycle
Registering a Fee Currency
Once your token implementsIFeeCurrency, it must be added to the on-chain allowlist in FeeCurrencyDirectory.sol through a governance proposal. The governance process ensures that fee currencies meet the necessary requirements for network stability.
If your token uses decimals other than 18, you will also need to deploy an adapter contract. See Adapters for Non-18-Decimal Tokens for details.