Web3.js (deprecated)
Web3.js has been sunset in 2024. Please consider using thirdweb or viem for your project.
Fee Abstraction with Web3.js
Fee Abstraction on Celo enables the use of stablecoins like cUSD, USDT and USDC as gas tokens.Requirements
- Web3.js v. > 4.13.1
Install the Celo Web3.js Plugin
For Celo’ specific features like Fee Abstraction transactions you need to install@celo/web3-plugin-transaction-types
as well as web3@4.13.1
or higher. This also adds utils like getCoreContractAddress
for fetching core contract address from onchain registry. This is useful to get the stablecoin addresses you are planning to use programmatically. Make sure they are listed in the FeeCurrencyWhitelist.sol.
web3.celo
is available and web3.eth
is “celo-aware”. “aware” means that if the tx has the feeCurrency
param, calling eth.sendTransaction
will use the celo cip64 serializer and be able to recognize the fee currency.
Here an example on how to use “feeCurrency” with cEUR.
Gas Price
When paying for transaction with an alternate feeCurrency token it is important to know the price of gas denominated in that token. You can useweb3.celo.populateTransaction
to make sure maxPriorityFeePerGas
, maxFeePerGas
, and gas
are filled properly.