Workshop: Building an Exchange on Celo using Celo Composer and Fiat-connect, Part II

Workshop: Building an Exchange on Celo using Celo Composer and Fiat-connect, Part II
none 0.0 0

Note: The resource above offers an in-depth explanation on the information summarized below.


Welcome to Part II of our workshop series, where we delve into the realm of Celo - a mobile-first, blockchain platform that makes financial tools accessible to anyone with a smartphone. As we build on the momentum of our previous session, we embark on the construction of an exchange using Celo Composer and Fiat-connect. To ensure a smooth journey, we have Femi and Habib spearheading the session, focusing on backend development with Node.js and solidifying our smart contracts.

Journey into Smart Contracts with Solidity and Celo Composer

A crucial element in creating our exchange lies in writing smart contracts. If you missed out on our last session, don’t worry! Head over to our YouTube channel and catch up on the first part of this workshop.

We focused on establishing our exchange Factory contracts, implementing wallets, and structuring our necessary functions in the previous workshop. Due to time constraints, we couldn’t quite dive into writing tests for our smart contracts, but we’ll be doing that now.

Constructing Test Scenarios

Our first step in testing is to ensure the accuracy of the implementation contract. By using Signer, we’re able to deploy our wallet implementation contracts, and subsequently, our exchange Factory. In this phase, we initialize our exchange Factory by passing the wallet address of the implementation.

We have carefully ensured that only the owner of our exchange Factory smart contract can call for the deployment of wallets. In essence, this means anyone wanting to interact with any of our wallets or the exchange must be the owner of the factory.

For the test, we aim to confirm the validity of the wallet address of each user when a new wallet is created. As the new wallet is created, the user UUID (Universally Unique Identifier) and the wallet are emitted.

In case of any errors during the wallet creation process, the test scenario is designed to revert to the initial state, making sure the operation doesn’t negatively affect the system.

Connecting Backend Server to Smart Contracts

With the basic testing of smart contracts done, we’ll now set up our backend server with Node.js and integrate it with our smart contracts. The purpose of the backend server is primarily to manage our user accounts, serving as an intermediary between the front-end UI and the smart contracts on the blockchain.

Once you’ve installed ether.js, you can start writing your API endpoints. The registration API, for instance, calls the newAdd function from the smart contract to create a new wallet for each user. It sends the user’s UUID, which we obtained during the sign-up process, to the newAdd function.

To display the users’ balances in the UI, we call the ERC20 token balance and cUSD balance functions from the smart contract. These functions return the balance of each asset, which the backend server then sends to the front-end.

For other actions like transfers or withdrawals, you locate the corresponding function in the smart contracts and call them from your API endpoints in a similar fashion.


The journey of creating an exchange on Celo using Celo Composer and Fiat-connect doesn’t stop here. With the foundation in place and the test scenarios constructed, we are well on our way to build the rest of the application. Although we focused on backend development in this session, these fundamental steps serve as a blueprint to connect other aspects of your application to the smart contracts on the blockchain. Remember, the process might seem complex, but understanding how each part works will guide you towards a successful implementation. Stay tuned for the next phase of our adventure!