This tutorial is designed for developers who have deployed dapps on ethereum before and now want to learn how to do the same with the Celo blockchain.
One of the biggest advantages of using Celo is that it is EVM compatible which means you can easily redeploy your dapps from ethereum blockchain to celo with a few changes in code (if at all required) and just changing the configuration file. In this tutorial, we will learn to do the same.
We will be redeploying the famous Pet Shop dApp. A complete walkthrough of pet shop is outside the scope of this tutorial, but you can find it here. The current tutorial is not limited to just this example and can be used as a guide to redeploy any other Ethereum smart contract to Celo.
Start by cloning the following repository
After cloning the repository, we have all the contracts required to deploy Pet Shop Dapp.
Let's install all the dependencies of the dapp by using
Now we have all the tools to start on your journey.
First, we need to find a way to interact with Celo blockchain. For this tutorial, we will be using
Celo CLIto do the same.
CeloCLI makes it extremely easy to interact with Celo Blockchain. It is a very handy tool for all celo developers. More information about CeloCLI can be found here.
After installing it, we need to make sure it is pointing to the correct endpoint. Let's check that by
Our node should be pointing to node: https://alfajores-forno.celo-testnet.org
In case your endpoint is something else, you can change it by using
Now our celocli is connected to
Alfajores Testnet. We need an account to work with. Let's use celocli for this. Use the following command to get a new account on testnet.
Our terminal should look something like this. (Everyone will have different values though!)
We will use this private key later on in this tutorial. Now that we have an account to work with, let's get some funds for signing transactions on the blockchain. Use Alfajores testnet faucet which can be found here. To check if we have received funds, use
To deploy our dapp to the Celo blockchain, all we need to do now is to change the
truffle-config.jsso that it can work with Celo blockchain. We will be taking help of
Wallet-localmade by Celo. We also need to install
dotenvto use our Private Key.
To install all of these, use
ContractKitis a library to help developers and validators to interact with the celo-blockchain and is well suited to developers looking for an easy way to integrate Celo Smart Contracts within their applications.
Wallet-Localprovides a local wallet instance to connect with contractKit. the
dotenvfile will be used to import Private Key that we added to .env file above into truffle-config without hardcoding it.
Paste the following code into our
Now our configuration file is all set to work with the Celo Blockchain.
Let's compile our smart contracts using
and after compiling is completed, let's migrate our smart contracts to Celo.
Congratulations! With that, we have deployed our Ethereum DApp to Celo.
Now we can use the same process to deploy any DApp we want to Celo. Don't let anything stop you, try cloning any project on ethereum and deploy it on Celo. Celo has wonderful opportunities for new projects.