Celo RPC API is incompatible with ethers.js
Description
Celo's block type differs from the block used in ethereum, this causes our RPC API to be incompatible with ethers.js (and most likely many other web3 clients)
See these issues where people have encountered problems https://github.com/ethers-io/ethers.js/issues/1735 https://github.com/ethers-io/ethers.js/discussions/2919 https://github.com/ethers-io/ethers.js/issues/2558 https://github.com/celo-org/celo-blockchain/issues/1738
Celo's block header lacks the following fields that exist in ethereum.
UncleHash
Difficulty
GasLimit
MixDigest
Nonce
BaseFee
So in order to provide an API that is compatible with ethers.js we should seek to somehow re-instate these missing fields. We could do this by actually adding the fields to the block or simply by filling them with fake data in RPC responses.
Although BaseFee and GasLimit are not currently part of the Celo block they are parameters of the system and are managed by smart contracts. So these can be added to the block in a meaningful way.
It's not so clear however what to do with UncleHash, Difficulty, MixDigest and Nonce, since these fields really do not exist in the Celo system. We could add them to the block or RPC responses, but we would need to fill them with dummy data. This could be more problematic than just not having them since people may then try to make important decisions based off the dummy data. Or may find that the dummy data causes other problems within their system.
This is preventing us from deploying on Celo/Alfajores atm as we require hardhat forking and ethers compatibility, see https://github.com/NomicFoundation/hardhat/issues/1966
ethers.js expects even length hex number for gasLimit:
We have been using ethers.js with an override to the formatter function to allow it to be used without gasLimit being present in the rpc responce.
About 2 days ago we started picking up errors on alfajores, I have removed our override and the error is still coming up
ethersProvider.getBlockWithTransactions(currentBlockHeight)
[Formatter.data (node_modules/@ethersproject/providers/lib/formatter.js:183:19),Object.gasLimit (node_modules/@ethersproject/providers/lib/formatter.js:399:20),Function.Formatter.check (node_modules/@ethersproject/providers/lib/formatter.js:380:40),Formatter._block (node_modules/@ethersproject/providers/lib/formatter.js:255:32),Formatter.blockWithTransactions (node_modules/@ethersproject/providers/lib/formatter.js:263:21),JsonRpcProvider.<anonymous> (node_modules/@ethersproject/providers/lib/base-provider.js:2077:71),step (node_modules/@ethersproject/providers/lib/base-provider.js:48:23),Object.next (node_modules/@ethersproject/providers/lib/base-provider.js:29:53),fulfilled (node_modules/@ethersproject/providers/lib/base-provider.js:20:58),processTicksAndRejections (internal/process/task_queues.js:93:5)] {
checkKey: 'gasLimit',
checkValue: '0x2160ec0'
} Error: invalid data; odd-length - 0x2160ec0
It seems that ethers.js expects this hex number to be of even length https://github.com/ethers-io/ethers.js/issues/614
Any update on this issue? +1 for blocking deployment
Celo is compatible with Ethers.js since December. Announcement here. If you’d like to share any feedback feel free to post it in this Github discussion.