Programmatic Setup
How dApp developers can use MetaMask to interact with the Celo network.
As of block height 31,056,500 (March 26, 2025, 3:00 AM UTC), Celo is no longer a standalone Layer 1 blockchain—it is now an Ethereum Layer 2! Some documentation may be outdated as updates are in progress. If you encounter issues, please file a bug report.
For the most up-to-date information, refer to our Celo L2 documentation.
Adding a Celo Network to MetaMask
To add a Celo Network to your dApp, you can use MetaMask's RPC API's wallet_addEthereumChain method. (See documentation).
Here is a JavaScript snippet you can use:
await window.ethereum.request({
method: 'wallet_addEthereumChain',
params: [<INSERT_NETWORK_PARAMS_HERE>],
});
Where it says INSERT_NETWORK_PARAMS_HERE, please replace with any of the following constants, depending on which network you'd like to connect to.
Mainnet
const CELO_PARAMS = {
chainId: "0xa4ec",
chainName: "Celo",
nativeCurrency: { name: "Celo", symbol: "CELO", decimals: 18 },
rpcUrls: ["https://forno.celo.org"],
blockExplorerUrls: ["https://explorer.celo.org/"],
iconUrls: ["future"],
};
Alfajores
const ALFAJORES_PARAMS = {
chainId: "0xaef3",
chainName: "Alfajores Testnet",
nativeCurrency: { name: "Alfajores Celo", symbol: "A-CELO", decimals: 18 },
rpcUrls: ["https://alfajores-forno.celo-testnet.org"],
blockExplorerUrls: ["https://celo-alfajores.blockscout.com/"],
iconUrls: ["future"],
};
Adding Tokens (e.g. cUSD, cEUR)
To watch an asset on a Celo network (e.g. cUSD, cEUR) in your dApp, you can use MetaMask's RPC API's wallet_watchAsset method. (See documentation).
Here is a JavaScript snippet you can use:
await window.ethereum.request({
method: "wallet_watchAsset",
params: {
type: "ERC20",
options: {
address: "<INSERT_ADDRESS_HERE>",
symbol: "<INSERT_SYMBOL_HERE>",
decimals: 18,
},
iconUrls: ["future"],
},
});
- Where it says
INSERT_ADDRESS_HERE, please replace with any of the following constants, depending on which network and which asset you'd like to connect to. - Where it says
INSERT_SYMBOL_HERE, please replace with the correct symbol for the asset you'd like to watch. For Celo Dollars, it'scUSDand for Celo Euros, it'scEUR.
View available token addresses for Celo assets to add to MetaMask here.
We strongly suggest that you disable your dApp's functionality when MetaMask is connected to a non-Celo network. MetaMask has an API for determining what network/chain you're connected to. See here for more documentation around that.