Skip to main content

5 posts tagged with "basics"

View All Tags
Go back

· 6 min read

Send, pay, and spend cryptocurrency like everyday money — all from the palm of your hand.

header

Hello Developers 🌱

Welcome to today’s post, where we’ll break down a blockchain topic into bite-sized pieces to help you learn and apply your new skills in the real world.

Today’s topic is Getting started with Valora on Celo.

Here’s a list of what we’ll cover 🗒

  • Step 1: Download Valora
  • Step 2: Create your Valora account
  • Step 3: Use the Valora app

By the end of this post, you’ll be up and running with Valora and ready to send Celo assets to your friends directly from your mobile phone.

Let’s go! 🚀

Introduction to Valora

Valora is a mobile wallet focused on making global peer-to-peer payments simple and accessible to anyone. It’s built on Celo and allows your to use your mobile phone number to send payments to your friends.

image

Valora syncs to your contacts list, which means you can make payments, send international remittances or simply split the bill with someone in your contact list — no matter where they are in the world.

✅ Step 1: Download Valora

To get started you’ll download Valora app. It is available in the App Store for iOS devices and Play Store for Android devices (links available on our home page.

image

Open the Valora app once it is done installing on your mobile device.

image

Read and navigate through the introductory screens and click Get Started.

image

✅ Step 2: Create your Valora account

From your Valora app, select create a new account to start setting up your new wallet. You may also Restore an account if you have an existing Valora account.

image

Terms and Conditions

Read and accept the terms and conditions.

image

Name and Profile

Create a name for your account and add a profile photo.

image

Pin Number

Create a memorable but secure pin number. You will need your PIN whenever you make a transaction, so make it memorable but not easy to guess.

image

Face ID

Click Turn on Face ID if you would like to secure your wallet and make it easier to access Valora.

image

Connect your phone number

Finally, connect your phone number to Valora. You will need to connect your own phone number if you wish to send funds directly to the phone number of your friends and family members.

image

You’ll receive 3 confirmation texts, each with a unique code. Just enter these in the respective fields. Hold tight, as the codes might take a few seconds to arrive. Once your number is connected, you can sync your contact information.

✅ Step 3: Use the Valora app

At this point, you have completed your account setup and can begin using Valora. Click Add Funds on the popup to fund your account from a debit card, bank account, or cryptocurrency exchange.

image

For now, you may close this popup to skip this step use Valora without adding funds. You’ll instead add funds later after you create your recovery phrase.

Select the menu on the top left of your app to view other screens on the Valora app. These screens include home, CELO, Dapps, Recovery Phrase, Add & Withdraw, Settings, and Help. This menu also shows your account address which you may share with others to receive transactions on Valora.

image

Home

You can send or request payments with your contacts from the home screen! To sync your contact list, tap send on your Valora home screen to send funds from a users name, phone number, address, or QR code.

image

Search and select the contact you want to send funds to and follow the prompts on the screen. If your contact doesn’t have Valora yet, don’t worry, the funds will be kept safe until they create their Valora account.

CELO

The CELO screen allows you to view the current price of CELO and your current CELO balance. You may also withdraw CELO and view all of your CELO activity from this screen.

image

Dapps

The Dapp screen is Valora’s Dapp explorer that allows you to view all Celo applications that integrate with Valora. You may use your Celo assets to make use of any application listed on this menu.

image

Selecting a Dapp will take you to its home page where you can learn more about getting started with the Dapp and its Valora integration.

Recovery Phrase

Set this up before funding your account. Your Valora recovery phrase is an extremely important part of your account. Without this phrase you may not be able to recover your account in the future, and with this phrase anyone can access your account.

image

Read more aboutwhat your Recovery Phrase is and why it is important.

Add & Withdraw

Now that you have a recovery phrase, you may add or withdraw Celo assets at any time using your debit card, bank account, or cryptocurrency exchange. Use the link provided for additional details on funding your account.

image

You can also send Celo assets to your account from any other wallet using the Account Address shown on the bottom of your menu.

Settings

The settings page allows you to manage important account information like your profile, security, data, and legal information. Use this anytime you’d like to edit important account details.

image

Help

The help page links you to frequently asked questions, forum, and contact information to allow you to get support from the Valora team. Use this anytime you run into issues with Valora or would like to contact the Valora team.

image

Supercharge

By adding Celo Dollars or Celo Euros to your account, you will automatically start earning rewards on those balances. Select the Rewards icon from the menu to learn more about supercharging your rewards.

image

Congratulations 🎉

That wraps up today’s topic on Getting started with Valora on Celo. You can review each of the items we covered below and check that you’re ready to apply these new skills.

Here’s a quick review of what we covered 🤔

  • Step 1: Download Valora
  • Step 2: Create your Valora account
  • Step 3: Use the Valora app

If you made it this far, you downloaded Valora, created an account, and understand how to use each of its basic features. You’re now ready to send Celo assets to your friends from your mobile phone.

GN! 👋

Go back

· 10 min read

How to deploy a smart contract to Celo testnet, mainnet, or a local network using Hardhat.

header

Hello Developers 🌱

Welcome to today’s post, where we’ll break down a blockchain topic into bite-sized pieces to help you learn and apply your new skills in the real world.

Today’s topic is Deploying on Celo with Truffle.

Here’s a list of what we’ll cover 🗒

  • Step 1: Environment setup​
  • Step 2: Project setup
  • Step 3: Write project code
  • Step 4: Configure deployment settings
  • Step 5: Compile and migrate your contract
  • Step 6: Deploy your Contract
  • Step 7: View your deployed contract
  • Step 8: Verify your smart contract

By the end of this post, you’ll be able to create, deploy, and interact with your smart contract on Celo testnet, mainnet, or localhost using Truffle.

Let’s go! 🚀

Introduction to Hardhat​

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum or Celo software. It helps developers manage and automate the recurring tasks that are inherent to the process of building smart contracts and dApps, as well as easily introducing more functionality around this workflow. This means compiling, running, and testing smart contracts at the very core.

image

tip

Learn more: If you are new to Hardhat check out Hardhat.org.

✅ Step 1: Environment setup​

Before getting started you’ll need to set up Celo in your local environment. You can do this on Mac or Windows and can find the details on docs.celo.org.

image

Celo projects include common dependencies like Nodejs, npm, nvm, yarn, git, and xCode. If you already have these installed you can follow this post to set up Celo specific dependencies.

Node v12.0.0

To build on Celo you’ll need to install and use node v12.0.0.

nvm install v12.0.0
nvm use v12.0.0
node --version

Celo Command Line Interface

The celocli lets you interact with the Celo Protocol smart contracts.

npm install -g @celo/celocli

image

Install Ganache (optional)

Ganache UI creates a local blockchain to help you deploy and test contracts. You can install and set up the UI from their website and can find more details in the Ganache docs.

image

tip

The @celo/ganache-cli is Celo’s version of Ganache. It doesn’t seem to be working for me but you can try installing it in your environment.

From the Ganache UI, create a new workspace on localhost:7545.

image

✅ Step 2: Project setup

Now that you have your environment setup, you’re ready to create your project! Open your terminal to create and navigate into a project folder.

mkdir celo-hardhat && cd celo-hardhat

image

Initialize an npm project

Initialize an npm project from within the project directory.

npm init -y

image

Install dotenv

Dotenv is a module that loads environment variables from a .env file. Install this now and you’ll use this to import information to your Truffle configuration file.

npm install dotenv

image

Initialize hardhat

Adding hardhat to your project allows you to easily build, test, and deploy smart contracts. You can install using npm or npx.

npm install --save-dev hardhat

or

npx hardhat

image

tip

Learn more: Follow the installation instructions and quickstart for additional details.

Customize project settings

After initializing hardhat have the chance to customize your project settings. In this post, we’ll Create a basic sample project and accept all of the default settings.

image

Open your project

Your project is set up and you’re ready to start building! Open your project in Visual Studio code or your preferred IDE.

code .

image

tip

You can launch VS Code from the command line by installing it in your shell path.

✅ Step 3: Write project code

To build your project you’ll write a smart contract, script , .env, and .gitignore file. You’ll also create an account, fund it with test tokens, and connect the account to your project.

Smart Contract Code

Hardhat provides a Greeter.sol contract to get you started. For this post, you’ll make your own files to give you a better idea of how everything works. Start by creating a file named HelloCelo.sol in the /contracts folder and add the Solidity code below.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
contract HelloCelo {
string public greet = "Hello Celo!";
}

image

tip

Learn more: Read the Solidity docs or Solidity by Example to learn more about the programming language for building smart contracts.

Script files

Hardhat also provides a sample-script.js file in the /scripts folder that you can use to deploy your smart contract. By default, it will deploy the Greeter.sol contract. Run the sample script to deploy this contract now!

Deploy Greeter.sol

npx hardhat run scripts/sample-script.js

image

To deploy the HelloCelo.sol contract you created, you’ll need to update the sample-script.js file to include the new smart contract information. To do this, replace lines 17–22 with the code below.

const HelloCelo = await hre.ethers.getContractFactory("HelloCelo");
const helloCelo = await HelloCelo.deploy();
await helloCelo.deployed();
console.log("HelloCelo deployed to:", helloCelo.address);

image

tip

If you created a different smart contract, update the const names, file requirement and deployment to match your new contract.

Deploy HelloCelo.sol

You can now re-run sample-script.js to deploy the HelloCelo.sol contract.

npx hardhat run scripts/sample-script.js

image

✅ Step 4: Create and fund your account

To deploy to the test or main Celo networks, you’ll need an account that is funded with CELO tokens. In this post, you’ll get set up to deploy for free on the Celo Alfajores test network!

Create an account

If you don’t already have an account you would like to use, you can run celocli account:newfrom your terminal to create one for this project.

celocli account:new

image

Fund your account

The Alfajores testnet faucet helps you fund your account with test tokens. Copy your address from the terminal and paste it into the site to fund your account. This should send you tokens within a few seconds.

image

Check account balance

If you’d like to check your new account balance, you can use celocli to make sure you received your test funds.

celocli account:balance 0xYOURADDRESS

image

Create .env file

A .env file will help you hide the sensitive information you need for your configuration file. Create a .env file in your root folder and add your account’s private key.

PRIVATE_KEY="5ead931ce4812310e31f84c471945b96a13098aa6dc8cf0d3f6f451a5dea56cc"

image

tip

See ignoring files for more information.

✅ Step 5: Configure deployment settings

The hardhat configuration file specifies the networks for your contract deployment. As of now, the sample-script.js file ​is deploying your contracts to a local blockchain on Hardhat.

Update hardhat.config

To deploy to Celo, you to update the configuration file to point to the Celo network. To do this, open hardhat-config.js in a text editor and replace its contents with this Celo configuration code.

Local network

Creating your new Ganache workspace earlier made a local blockchain at localhost:7545. The local configuration connects to this local blockchain.

localhost: {
url: "http://127.0.0.1:7545"
},
tip

If you choose to Set up a Local Development Chain, your blockchain will also be hosted on a private network on localhost. This same configuration can be used to connect to the local development chain.

Alfajores test network

The alfajores configuration uses Forno to connect you to Alfajores using the private key in your .env file.

alfajores: {
url: “https://alfajores-forno.celo-testnet.org",
accounts: [process.env.PRIVATE_KEY],
chainId: 44787,
},

Celo main network

The celo configuration uses Forno to connect you to mainnet using the private key in your .env file. This tutorial will use Alfajores but you can to deploy to the main network whenever you’d like.

celo: {
url: "https://forno.celo.org",
accounts: [process.env.PRIVATE_KEY],
chainId: 42220,
},
tip

Forno is a cLabs hosted node service for interacting with the Celo network. This allows you to connect to the Celo Blockchain without having to run your own node.

✅ Step 6: Deploy your contract

You’ve done the hard part and it’s now time to deploy your contract to Celo! Run any of the following commands from your root project directory to deploy to Celo.

Deploy to Alfajores

This post got you set up to deploy on Alfajores. Try it out now! If this works you can skip the other deployment options and move on to the next step.

npx hardhat run scripts/sample-script.js --network alfajores

Deploy to Mainnet

Replace the private key in .env with a Celo Mainnet account that has Celo. Once you’ve done that you’ll be ready to deploy to Mainnet.

npx hardhat run scripts/sample-script.js --network celo

Deploy to Local Host

Open Ganache (installation instructions at beginning of the post) and create a workspace on localhost:7545. Then you’ll be able to deploy to localhost.

npx hardhat run scripts/sample-script.js --network localhost

✅ Step 7: View your deployed contract

Now that you deployed your contract, you can view it in the Celo block explorer (known as BlockScout. Copy your contract address from the terminal and navigate to the block explorer to search for your deployed contract.

  • Switch to your network using the dropdown by the search bar.
  • Navigate to BlockScout and select the network of your deployed contract.
  • Paste your contract address from the terminal window and search for it in BlockExplorer.

image

tip

Learn more about building and deploying dApps using the HardHat documentation.

✅ Step 8: Verify your smart contract

For people to use and interact with your contract, they’ll want to be able to view the smart contract code you created. Verifying a smart contract allows people to to do this from within the Celo Block Explorer.

Using Blockscout​

Navigate to the Code tab on the Explorer page for your contract’s address Click Verify & Publish to enter the smart contract verification page

image

  • Upload your smart contract (example: HelloCelo.sol) and its .json file (example: HelloCelo.json) found in build > contracts folder.

image

  • Click Verify & Publish
  • Navigate to the Contract Address Details Page in the block explorer to, use the Code, Read Contract, and Write Contract panels to view and interact with your deployed smart contract.

Using Hardhat-deploy plugin​

You can read an in depth guide about how to deploy and verify contracts on Celo programmatically using the hardhat-deploy plugin here.

Congratulations 🎉

That wraps up today’s topic on Deploying on Celo with Hardhat. You can review each of the items we covered below and check that you’re ready to apply these new skills.

Here’s a review of what we covered 🤔

  • Step 1: Environment setup​
  • Step 2: Project setup
  • Step 3: Write project code
  • Step 4: Configure deployment settings
  • Step 5: Compile and migrate your contract
  • Step 6: Deploy your Contract
  • Step 7: View your deployed contract
  • Step 8: Verify your smart contract

If you run into any issues, try reviewing the content or searching online to explore each topic in more detail. Hopefully, you’ve learned a few things about Deploying on Celo with Hardhat that you can apply in the real world.

GN! 👋

Go back

· 6 min read

How to deploy a smart contract to Celo testnet, mainnet, or a local network using Hardhat.

header

Hello Developers 🌱

Welcome to today’s post, where we’ll break down a blockchain topic into bite-sized pieces to help you learn and apply your new skills in the real world.

Today’s topic is How to quickly build an NFT collection on Celo.

Here’s a list of what we’ll cover 🗒

  • Step 1: Connect to MetaMask
  • Step 2: Upload your NFT with Pinata
  • Step 3: Create your Smart Contract (low-code)
  • Step 4: Deploy your Smart Contract
  • Step 5: Mint your NFT

By the end of this post, you’ll have an NFT collection built using MetaMask, Celo, Pinata, IPFS, OpenZeppelin, and Remix. These tools allow you to create, deploy, and manage NFTs quickly without writing any code.

Let’s go! 🚀

Before getting started

This post uses a variety of tools to help you quickly deploy your NFT on Celo. While the post allows you to follow along with no background in these tools, it may help to review some of the links below.

✅ Step 1: Connect to MetaMask

MetaMask allows you to connect to the Celo blockchain from your browser. To get started, install the Metamask browser extension.

image

  • Add Alfajores Testnet to MetaMask using the manual setup option here
  • Add CELO to your test account using the Alfajores Testnet Faucet
tip

Learn more: Check out 3 Simple Steps to Connect your MetaMask Wallet To Celo for more details.

✅ Step 2: Upload your NFT ​with Pinata

Pinata allows you to easily upload files to IPFS to use as your NFT.

image

To get started, go to Pinata and log in or sign up for an account.

image

Once logged in, select the + Upload button

image

Choose the files you would like to upload and complete the upload process.

image

You should now see the name and content identifier (CID) hash for each file.

image

You’ll now prepare the token metadata. The example uses a folder named prosper factory metadata. View the contents of the folder here.

image

Select any file to view the NFT metadata from within a browser that supports IPFS (example: Brave Browser) to see the unique image reference.

{
"image": "ipfs://QmVKCcW7c5aUs3GzW92atgFUz7N6rox7EzeibEbyJ6jBMi"
}

Next, create a folder containing metadata for each NFT you’d like to create. Upload a folder containing all of the token metadata to Pinata. This will make your NFT data publicly available.

image

This example uses a folder name prosper factory metadata. You can view the contents of the folder here. The folder contains 14 files, numbered 0–13. The names of these files are important. These file names correspond to the token ID of each NFT that will be created by the contract. Make sure that there are no extensions (.txt, .json, .jpeg, .png) on your files.

✅ Step 3: Create your Smart Contract (low-code)​

Now that your NFT image is on IPFS, you’ll create and deploy a smart contract. In this post, you’ll use OpenZeppelin, a well known smart contract library to create your smart contract without writing any code.

image

Select ERC721 as your token choice and learn more about ERC721 here.

image

  • Enter your token information (name, symbol).
  • Enter the Content Identifier (CID) from Pinata as the Base URI

image

  • Select Mintable and Auto increment ids. This gives each NFT a unique identifier that increments as new NFTs are minted.
  • Select Ownable. This restricts minting to the owner of the contract. The owner is the address you used to deploy your smart contract.

image

✅ ​Step 4: Deploy your Smart Contract

Remix is an online tool that allows you to develop, deploy, and manage smart contracts on Celo. Now that your contract is complete, you’ll use Remix to interact with your smart contract.

image

  • From the OpenZeppelin Wizard, click Open in Remix.
  • Remix will open with your OpenZeppelin contract available.
  • Click the blue button labeled Compile Contract.

image

After compiling the contract, click the Ethereum logo on the left panel to open the Deploy & Run transactions tab.

image

  • In the Environment dropdown, select Injected Web3 to connect Remix to MetaMask.
  • Check that MetaMask is connected to the correct network (example: Alfajores Testnet). This network will appear as Custom (44787).

image

Select the contract you would like to deploy (example: ProsperityFactory).

image

  • Click Deploy and confirm the transaction from MetaMask.
  • View your deployed contract from the dropdown on the bottom left corner of Remix.

image

Expand the dropdown to see each of your contract’s functions.

✅ Step 5: Mint your NFT

You’re finally ready to mint your NFT!

  • Call the safeMint function using your wallet address as the input.
  • Confirm the transaction in MetaMask to mint your first NFT.

image

You can verify that the token was minted by calling the tokenURI function with the expected token ID. Calling the contract with tokenURI = 0 will return the NFTs IPFS reference

image

This IPFS reference will show the token metadata for that NFT.

Example Image

{
"image": "ipfs://QmVKCcW7c5aUs3GzW92atgFUz7N6rox7EzeibEbyJ6jBMi"
}

Navigate to the IPFS reference to view the image for the token.

image

Congratulations 🎉

That wraps up today’s topic on how to quickly build an NFT collection on Celo. You can review each of the items we covered below and check that you’re ready to apply these new skills.

Here’s a quick review of what we covered 🤔

  • Step 1: Connect to MetaMask
  • Step 2: Upload your NFT with Pinata
  • Step 3: Create your Smart Contract (low-code)
  • Step 4: Deploy your Smart Contract
  • Step 5: Mint your NFT

Hopefully, you now have an NFT collection built using MetaMask, Celo, Pinata, IPFS, OpenZeppelin, and Remix. Use can now use these tools whenever you’d like to create, deploy, and manage NFTs quickly without writing any code.

GN! 👋

Go back

· 5 min read

How the Celo light client became 1.7 million times lighter than Ethereum.

header

Hello Developers 🌱

Welcome to today’s post, where we’ll break down a blockchain topic into bite-sized pieces to help you learn and apply your new skills in the real world.

Today’s topic is Plumo: An Ultralight Blockchain Client on Celo.

Here’s a list of what we’ll cover 🗒

  • ✅ Introduction to Plumo
  • ✅ Why is Plumo important?
  • ✅ A Simple Plumo Demonstration
  • ✅ Additional Plumo Resources

By the end of this post, you’ll have a basic introduction to Plumo, tried a demo showcasing Plumo’s functionality, and have resources to help you learn more about Celo’s ultralight blockchain client.

Let’s go! 🚀

✅ Introduction to Plumo

Celo has announced the arrival of Plumo, Celo’s advanced ZK-snark-based light client protocol. Plumo, meaning feather in Esperanto, lives up to its name as an incredibly light client for the Celo blockchain.

Previously, Celo’s previous light client protocol was around 17,000 times lighter than Ethereum’s light client protocol. With Plumo, Celo is now 1.7 million times lighter.

With Plumo, Celo is now 1.7 million times lighter than Ethereum!

Anyone can now generate Plumo snark proofs that let dApps sync with the chain in a fully trustless manner. cLabs is hosting the first server that’s generating these proofs daily but anyone can run one of these.

Celo has also announced the launch of a WASM based library that lets web apps verify Plumo proofs, sync with the chain, and then verify state that’s happening as it’s fetched from full nodes on the network.

This means that for the first time in the crypto industry, applications will be able to connect to the P2P network, connect to the chain in a fully trustless manner, sync near instantly and verify state that they can request from any full node. All this is possible without having to have any trust assumptions, with those full nodes.

✅ Why is Plumo important?

Syncing the latest state of a blockchain can be a resource-intensive task, driving users towards centralized services offering easier access. To expand decentralized services to anyone with a mobile phone, Celo created a consensus-agnostic compiler for constructing ultralight clients. This provides secure and highly efficient blockchain syncing via a sequence of SNARK-based state transition proofs with formally proven security.

Plumo allows Celo nodes sync to the Celo blockchain faster with less data.

Devices can sync the latest network state summary in just a few seconds even on a low-end mobile phone. Using Plumo, each transition proof covers four months of blockchain history and can be produced for just \$25.

✅ A Simple Plumo Demonstration

You can see Plumo in action here using the Celo Wallet.

Create New Account

Once on the site, either Create New Account or Use Existing Account if you would like to use your Celo account. Follow the instructions provided to get your account details, set your password, and login to your wallet.

image

Your Celo Wallet

Once logged in, you’ll be able to view your account details.

image

Do you notice anything amazing? 🤔

Not yet?

Select the button that says Connected on the bottom right of your screen.

image

This will show you the Connection Status. Take note of the Last Block Number and close this window. Here it is 12946675.

image

Wait a few seconds… 🦗🦗🦗

Now select the Connected button again!

image

You should see that the Last Block Number is showing a newer block than it was before. In the image above the block is 12946680…an entire 5 blocks have synced since last checked.

What you’re seeing is one of many possible examples of Plumo in action. It’s live syncing Celo network data to your device in real-time using an ultralight client. This could happen on a computer, a tablet, a phone, and even a cheap phone with low bandwidth-and before Plumo it could never happen so fast.

✅ Additional Plumo Resources

A large amount of research, development, and innovation has gone into creating this light client, and there are many resources you can explore to learn more. Here are a few to help you get started.

Plumo Whitepaper

This whitepaper describes the design of Plumo as a method to develop scalable interoperable blockchains using ultra light validation systems.

image

tip

Learn more: Plumo Whitepaper

Plumo Documentation

Introduction to Plumo Ultralight Sync, its core concepts, architecture, process, and implementation.

image

tip

Celo Tech Talks Plumo

In this Celo Tech Talk, Michael Straka, Cryptography Engineering Partner will introduce you to the Plumo Protocol.

tip

Watch more: Kobi Gurkan on Plumo & Kobi Gurkan on Optimistic SNARK setups for Plumo

Additional Resources

Congratulations 🎉

That wraps up today’s topic on Plumo: An Ultralight Blockchain Client on Celo. You can review each of the items we covered below and check that you’re ready to apply these new skills.

Here’s a quick review of what we covered 🤔

  • ✅ Introduction to Plumo
  • ✅ Why is Plumo important?
  • ✅ A Simple Plumo Demonstration
  • ✅ Additional Plumo Resources

At this point, you’ve read a basic introduction to Plumo, tried a demo showcasing Plumo’s functionality, and have resources to help you access more details about Celo’s ultralight blockchain client.

GN! 👋

Go back

· 10 min read

How to deploy a smart contract to Celo testnet, mainnet, or a local blockchain using Truffle.

header

Hello Developers 🌱

Welcome to today's post, where we'll break down a blockchain topic into bite-sized pieces to help you learn and apply your new skills in the real world. Today's topic is Deploying on Celo with Truffle.

Here's a list of what we'll cover 🗒

  • Step 1: Environment setup
  • Step 2: Project setup
  • Step 3: Write project code
  • Step 4: Create and fund your account
  • Step 5: Configure deployment settings
  • Step 6: Compile and migrate your contract
  • Step 7: Deploy your contract
  • Step 8: View your deployed contract
  • Step 9: Verify your smart contract

By the end of this post, you'll be able to create, deploy, and interact with your smart contract on Celo testnet, mainnet, or localhost using Truffle.

Let's go! 🚀

Introduction to Truffle​

Truffle is a world-class development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM). By creating a Truffle project and editing a few configuration settings you can easily deploy your project on Celo.

image

tip

Learn more: If you are new to Truffle check out the Truffle docs.

✅ Step 1: Environment setup

Before getting started you'll need to set up Celo in your local environment. You can do this on Mac or Windows and can find the details on docs.celo.org.

image

Celo projects include common dependencies like Nodejs, npm, nvm, yarn, git, and xCode. If you already have these installed you can follow this post to set up Celo specific dependencies.

Node v12.0.0

To build on Celo you’ll use node v12.0.0.

nvm install v12.0.0
nvm use v12.0.0
node --version

Celo Command Line Interface

The celocli lets you interact with the Celo Protocol smart contracts.

npm install -g @celo/celocli

image

Install Truffle

Truffle lets you to develop, test, and deploy dApps on Celo.

npm install -g truffle

Install Ganache

Ganache UI creates a local blockchain to help you deploy and test contracts. You can install and set up the UI from their website and can find more details in the Ganache docs.

image

tip

The @celo/ganache-cli is Celo’s version of Ganache. It doesn’t seem to be working for me but you can try installing it in your environment.

From the Ganache UI, create a new workspace on localhost:7545.

image

✅ Step 2: Project setup

Now that you have your environment setup, you’re ready to create your project! Open your terminal to create and navigate into a project folder.

mkdir celo-truffle && cd celo-truffle

image

Initialize an npm project

Initialize an npm project from within the project directory.

npm init -y

image

Install hdwallet-provider

Truffle/hdwallet-provider lets you sign Celo transactions for addresses derived from a mnemonic or private key. You can install this now and you’ll use it later when configuring your project.

npm install @truffle/hdwallet-provider --save

image

Install dotenv

Dotenv is a module that loads environment variables from a .env file. Install this now and you’ll use this to import information to your Truffle configuration file.

npm install dotenv

image

Initialize Truffle

Initializing Truffle creates your project’s truffle environment. Use truffle init to start up your truffle project!

truffle init

image

Open your project

Your project is set up and you’re ready to start building! Open your project in Visual Studio code or your preferred IDE.

code .

image

tip

You can launch VS Code from the command line by installing it in your shell path.

✅ Step 3: Build your project

To build your project you’ll write a smart contract, migrations, .env, and .gitignore file. You’ll also create an account, fund it with test tokens, and connect the account to your project.

Smart contract code

Create a file named HelloCelo.sol in the /contracts folder and add the Solidity code below.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
contract HelloCelo {
string public greet = "Hello Celo!";
}

image

tip

Learn more: Read the Solidity docs or Solidity by Example to learn more about the programming language for building smart contracts.

Create migrations file

Create a file named 2_deploy_contracts.js in the /migrations folder and add the code below.

var HelloCelo = artifacts.require('HelloCelo')
module.exports = function (deployer) {
deployer.deploy(HelloCelo)
}

image

tip

If you created a different smart contract, update the variable name, file requirement and deployment to match your new contract.

✅ Step 4: Create and fund your account

To deploy to the test or main Celo networks, you’ll need an account that is funded with CELO tokens. In this post, you’ll get set up to deploy for free on the Celo Alfajores test network!

Create an account

If you don’t already have an account you would like to use, you can run celocli account:new from your terminal to create one for this project.

celocli account:new

image

Fund your account

The Alfajores testnet faucet helps you fund your account with test tokens. Copy your address from the terminal and paste it into the site to fund your account. This should send you tokens within a few seconds.

image

Check account balance

If you’d like to check your new account balance, you can use celocli to make sure you received your test funds.

celocli account:balance 0xYOURADDRESS

image

Create .env file

A .env file will help you hide the sensitive information you need for your configuration file. Create a .env file in your root folder and add your account’s private key.

PRIVATE_KEY="5ead931ce4812310e31f84c471945b96a13098aa6dc8cf0d3f6f451a5dea56cc"

image

Create .gitignore file

A .gitignore file will allow you to ignore certain files if you add this project to git or GitHub. Create a .gitignore file in your root directory and add the code below to ignnore your node_modules, .DS_Store and .env files.

# dependencies
/node_modules
# Mac users
.DS_Store
#hidden files
.env

image

tip

See ignoring files for more information.

✅ Step 5: Configure deployment settings

The truffle configuration file specifies the networks for your contract deployment. By default, it is set up to deploy to the Ethereum network but you can update this information to deploy to any Celo network.

Update Truffle.config

Open truffle-config.js in a text editor and replace its contents with this Celo configuration code. This updates the truffle.config.js file to point toward Celo networks.

image

Local network

Creating your Ganache workspace earlier made a local blockchain at localhost:7545. The local configuration connects to this local blockchain.

local: {
host: "127.0.0.1",
port: 7545,
network_id: "*"
}

Remote node connections

If you’re not running your own node, you can connect to remote nodes using Forno. Forno is a Celo node service that lets you connect to the Celo Alfajores Test Network and Celo Mainnet.

Alfajores test network

The alfajores configuration uses Forno to connect you to Alfajores using HDWalletProvider and the private key in your .env file.

alfajores: {
provider: function() {
return new HDWalletProvider(process.env.MNEMONIC, "https://alfajores-forno.celo-testnet.org")
},
network_id: 44787,
gas: 20000000
}

Celo main network

The celo configuration uses Forno to connect you to mainnet using HDWalletProvider and the private key in your .env file. This tutorial will use Alfajores but you can to deploy to the main network whenever you’d like.

celo: {
provider: function() {
return new HDWalletProvider(process.env.MNEMONIC, "https://forno.celo.org")
},
network_id: 42220,
gas: 4000000
}
tip

Learn more: To deploy to Celo Mainnet, follow 3 simple steps to connect your MetaMask wallet to Celo and deploy to this account instead of your test account.

✅ Step 6: Compile and migrate your contract

Compiling and migrating your contract prepares the code to deploy on a Celo network. This will also help you catch any errors and debug your code.

Compile Contract

Compile the Solidity code into Ethereum bytecode. This command will compile any new or updated Solidity (.sol) contracts found in /contracts.

truffle compile

image

Now you should see HelloCelo.json in your /build folder.

tip

Learn more about compiling contracts with Truffle here.

Migrate Contract

Truffle migrate compiles AND migrates your contract. In the future you can run truffle migrate to complete both steps.

truffle migrate

image

✅ Step 7: Deploy your Contract​

For this post, use truffle deploy --network alfajores to deploy to Alfajores but it’s easy to deploy to local or mainnet whenever you’d like!

truffle deploy --network alfajores
truffle deploy --network celo
truffle deploy --network local

Deploy with — reset​ (optional)

You can edit contracts and redeploy at any time using the commands above. If for any reason you’d like to redeploy a contract that you didn’t edit you can use the reset flag. This will redeploy each contract to a new contract address.

truffle deploy --network NETWORK --reset
truffle migrate --network NETWORK --reset
tip

Save contract addresses for future reference. If you lose it, go to the block explorer to review your wallet transactions for contract creation and its response. Truffle saves deployment information, like transaction hashes and contract addresses, in JSON files in ./build/contracts/.

✅ Step 8: View your deployed contract

Now that you deployed your contract, you can view it in the Celo block explorer (known as BlockScout. Copy your contract address from the terminal and navigate to the block explorer to search for your deployed contract.

  • Switch to your network using the dropdown by the search bar.
  • Navigate to BlockScout and select the network of your deployed contract.
  • Paste your contract address from the terminal window and search for it in BlockExplorer.

image

tip

Learn more about exploring the Celo network and smart contract details in BlockScout here.

✅ Step 9: Verify your smart contract​

For people to use and interact with your contract, they’ll want to be able to view the smart contract code you created. Verifying a smart contract allows people to to do this from within the Celo Block Explorer.

  • Navigate to the Code tab on the Explorer page for your contract’s address
  • Click Verify & Publish to enter the smart contract verification page

image

  • Upload your smart contract (example: HelloCelo.sol) and its .json file (example: HelloCelo.json) found in build > contracts folder.

image

  • Click Verify & Publish
  • Navigate to the Contract Address Details Page in the block explorer to use the Code, Read Contract, and Write Contract panels to view and interact with your deployed smart contract.

Congratulations 🎉

That wraps up today’s topic on Deploying on Celo with Truffle. You can review each of the items we covered below and check that you’re ready to apply these new skills.

Here’s a review of what we covered 🤔

  • Step 1: Environment setup
  • Step 2: Project setup
  • Step 3: Write project code
  • Step 4: Create and fund your account
  • Step 5: Configure deployment settings
  • Step 6: Compile and migrate your contract
  • Step 7: Deploy your contract
  • Step 8: View your deployed contract
  • Step 9: Verify your smart contract

If you run into any issues, try reviewing the content or searching online to explore each topic in more detail. Hopefully, you’ve learned a few things about Deploying on Celo with Truffle that you can apply in the real world.

GN! 👋