🚀Deploying Your Contract

Ready to write a smart contract, interact with it and finally deploy & verify it?

Tip: If you have not watched the first video, go back to Installation & Setup to understand how to set up your Celo composer environment and understand its folder structure.

Goal

Visit OpenZeppelin Contract Wizard

Open https://docs.openzeppelin.com/contracts/4.x/wizard in your browser. You will see the contract wizard with the ERC20 token contract as default, next do the following:

You should be looking at something like this by now

Create the CeloCommunityToken.sol

Now go back to your code editor, open packages/hardhat/contracts and create a CeloCommunityToken.sol file. Copy the code from the wizard and paste inside the newly created file.

Now cd from your terminal back to packages/hardhat install the Openzeppelin library that our smart contract is importing from.

Run: code

yarn add @openzeppelin/contracts -D

This will install the open Openzeppelin library, you can check your node_modules folder if you would like to inspect the library and browse its code.

Finally, add an extra modifier to the mint function. Just after onlyOwner modifier add whenNotPaused modifier.

Add Deploy Script

Open src/hardhat/contracts/deploy/00-deploy.js and update it with the belwo snippet.

  await deploy("CeloCommunityToken", {
    from: deployer,bas
    log: true,
  });

Next, update the export to include CeloCommunityToken so it can match below.

module.exports.tags = [
  "Greeter",
  "Storage",
  "SupportToken",
  "CeloCommunityToken",
];

And finally, in your root folder, run the below command to deploy your newly added smart contract.

PRIVATE_KEY={YOUR_PRIVATE_KEY_HERE} yarn hardhat:deploy

Above you would see our contract is now being deployed to address 0x2204d0117327A***** . Your own address will differ from mine, and so is everyone else. Hold down the cmd/ctrl and click on tx in your terminal, it will open up the transaction details page on Celo Alfajores explorer using the transaction hash to search.

As you can see in the image above, our new contract was created and immediately minted 1,000 CCT tokens to our address. To view this balance, open your Metamask, click import tokens then copy the smart contract address and paste it into the field that says Token Contract Address the rest will auto fill itself.

Now you should see your 1,000 CCT token balance.

Interact with Contract UI

Celo composer comes with a contract component that allows you call and transact with the functions of the smart contract without having to write a single line of code. If you don't have your react app front end included in Celo composer running by now, in a new terminal on the celo composer project root directory run:

yarn react-app:dev

Open http://localhost:3000 on your browser and click on the CeloCommunnityToken tab, you will see all of the public functions of the smart contracts that you can execute.

  • The functions marked view are readonly functions that don't cost us gas fees.

  • The non payable functions make changes to the contract states but are not payable i.e. do not direct accept CELO if you send it to them.

  • The functions marked payable are state-changing functions and require that yous end CELO to them while calling it.

View functions have call buttons while state-changing functions such as payable and non payable ones have buttons called transact.

Perform the following tasks:

Last updated