Building Back End Decentralised Payment App on Celo using JavaScript and Solidity (Part2)

Building Back End Decentralised Payment App on Celo using JavaScript and Solidity (Part2)
none 0.0 0

Blockchain technology is rapidly gaining traction in various sectors, one of which is the financial industry. Celo, a mobile-first blockchain platform, aims to provide efficient and affordable financial tools for everyone, thereby contributing significantly to the decentralized financial world.

In this article, we will delve into building a back-end decentralized payment application using Celo, JavaScript, and Solidity.


Setting Up the Development Environment

We’ll start by initializing a new node.js project and installing Hardhat:

mkdir celo-payment-app
cd celo-payment-app
npm init -y
npm install --save-dev hardhat

Then, we create a new Hardhat project:

npx hardhat

During the setup, choose ‘Create a JavaScript project’.

Contract Development

We’ll write our smart contract in Solidity. Let’s create a new file in the contracts directory called PaymentProcessor.sol

Our contract will accept payments and store the necessary transaction data.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract PaymentProcessor {
    address public admin;
    mapping(address => uint256) public balances;

    constructor(address _admin) {
        admin = _admin;

    function pay() external payable {
        require(msg.value > 0, "Payment must be positive");
        balances[msg.sender] += msg.value;
        emit PaymentDone(msg.sender, msg.value);

    event PaymentDone(address payer, uint256 amount);

Here, we’re creating a simple contract that allows users to send payments and tracks their balances. Whenever a payment is received, a PaymentDone event is emitted.

Compiling the Contract

Hardhat makes it easy to compile contracts and manage different Solidity versions. Let’s compile our contract:

npx hardhat compile

Testing the Contract

Writing tests for our smart contract is crucial. Let’s write a test in the test directory:

mkdir test
touch test/PaymentProcessor.js

In test/PaymentProcessor.js:

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("PaymentProcessor", function () {
  it("Should receive and record payments", async function () {
    const PaymentProcessor = await ethers.getContractFactory("PaymentProcessor");
    const paymentProcessor = await PaymentProcessor.deploy();
    await paymentProcessor.deployed();

    await{value: ethers.utils.parseEther("1.0")});

    expect(await paymentProcessor.balances(owner.address)).to.equal(ethers.utils.parseEther("1.0"));

Now, run the tests:

$ npx hardhat test


Hardhat also aids in contract deployment. In the scripts directory:

$ mkdir scripts
$ touch scripts/deploy.js

And in scripts/deploy.js:

const hre = require("hardhat");

async function main() {
    const PaymentProcessor = await hre.ethers.getContractFactory("PaymentProcessor");
    const paymentProcessor = await PaymentProcessor.deploy();
    await paymentProcessor.deployed();
    console.log("PaymentProcessor deployed to:", paymentProcessor.address);

 => {

Now, we can deploy the contract:

$ npx hardhat run scripts/deploy.js

Integrating with Celo

To allow our DApp to interact with Celo, we need to connect our contract to a Celo network. Hardhat makes it easy to switch between different networks. We’ll add a network configuration in the hardhat.config.js file:

module.exports = {
  solidity: "0.8.0",
  networks: {
    celo: {
      url: "",
      accounts: [process.env.CELO_PRIVATE_KEY]

We are now able to deploy our contract on the Celo network using:

$ npx hardhat run --network celo scripts/deploy.js

Now that we’ve created and deployed our smart contract, the next step is to build a front-end application that interacts with it. But that’s a topic for another article.


In summary, this guide should provide a clear insight into how you can leverage JavaScript, Solidity, and Hardhat to build a back-end decentralized payment application on Celo. It’s fascinating to see how these tools work together to deliver powerful, decentralized applications, and I encourage you to explore further.

About the Author

Aborode Prime Olusegun is a Growth Marketer and Data Analyst. He’s got a huge interest in Web3 and the decentralisation that it offers. Twitter




This seems to be in the wrong folder. If its a new request, please move it to Proposals > New Request


thank you for the correction. I have just done that


Congratulations on being among the highest voted proposals for this week! I’m moving this to todo so that you can get started on this project. :mortar_board: :seedling:


I’ll be reviewing this @olusegun


can i know why this was moved in to publish section


Hello @ishan.pathak2711 What errors would you like me to correct?


First please tell me , were you said to move the article in the publish section by the reviewer?


I did not move the article. I don’t think I am supposed to do that.

The reviewer moved the article after reviewing it.

Is there any problem or changes you noticed I should work on @ishan.pathak2711?


No need




Is there any existing article in the community that solves this. If none, can you create a proposal and interested folks like can vote it.


You can read the front end resources article here.


The link to the part 1 should be inside your tutorial itself. It makes things easier.

Great content sir.

1 Like

It’s linked in the requirements EmiriDbest


Nice one sir…apologies for not noticing it.
I suggest you put it in introduction and make it more obvious that its the first part of the work…probably through a more detailed sentence.

Thanks for your efforts.

1 Like

@olusegun this is cool, :+1:

I look forward to more complex implementation.