Reader small image

You're reading from  Developing Blockchain Solutions in the Cloud

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781837630172
Edition1st Edition
Right arrow
Authors (2):
Stefano Tempesta
Stefano Tempesta
author image
Stefano Tempesta

Stefano Tempesta is a technologist working at the crossroads of Web2 and Web3 to make the internet a more accessible, meaningful, and inclusive space. Stefano is an ambassador of the use of AI and blockchain technology for good purposes. A former advisor to the Department of Industry and Science, Australia, on the National Blockchain Roadmap, he is cofounder of Aetlas, a decentralized climate action and sustainability network with a mission to source verified carbon units for liquidity and carbon asset monetization. A passionate traveler, a poor musician, and an avid learner of new technologies and (programming) languages, Stefano holds three citizenships and speaks fluent English, Italian, and terrible Ukrainian.
Read more about Stefano Tempesta

Michael John Peña
Michael John Peña
author image
Michael John Peña

Michael John Peña, an engineer and Microsoft MVP, excels in tech innovation and leadership. As a data partner at Playtime Solutions, he spearheads projects utilizing Azure, big data, and AI, enhancing data-driven decision-making. With roles ranging from CTO to software engineer, MJ's expertise covers web/app development, cloud computing, blockchain, and IoT. His commitment to lifelong learning and sharing knowledge—underscored by his work with start-ups and as a technical advisor—drives industry advancements in finance, construction, and more. MJ values inclusivity and actively fosters diverse, collaborative environments.
Read more about Michael John Peña

View More author details
Right arrow

Building a Decentralized Marketplace on AWS

Welcome to this hands-on lab, where you’ll learn how to build a decentralized marketplace while leveraging the power and flexibility of Amazon Web Services (AWS) and blockchain technology. In today’s digital age, centralization has often led to single points of failure, potential data breaches, and the overarching power of a single entity over a marketplace. This lab aims to introduce you to the technical foundations of creating a marketplace that is not only decentralized but also secure, transparent, and scalable.

In this chapter, we’ll dive into the following main topics:

  • The solution architecture for the decentralized marketplace
  • The hosting infrastructure in AWS
  • Setting up a blockchain network in AWS
  • Creating and deploying the marketplace in AWS

Technical requirements

Building a blockchain solution often requires integration with third-party systems. In this case, we’re going to leverage the following services in AWS, all of which complement the marketplace application by adding computing and storage capabilities:

  • Amazon Elastic Compute Cloud (EC2): Virtual servers in the cloud for running an Ethereum node
  • Amazon Relational Database Service (RDS): A relational database service for off-chain data
  • Amazon Simple Storage Service (S3): A storage service for unstructured data, such as files

We are going to run the marketplace on a blockchain network. Our choice for this lab is Ethereum. Ethereum is open source and can easily be deployed on Virtual Machines (VMs) in AWS. The relevant smart contracts will be published on the Ethereum mainnet, as described later in this chapter.

What to expect

This lab comprises step-by-step configuration guides, code samples, and best practices to ensure we successfully...

Solution architecture and hosting infrastructure

Building a decentralized marketplace on AWS involves several key aspects and software components that collectively contribute to the creation of a robust, scalable, and secure platform. The following figure depicts the key aspects of a decentralized app built on a public cloud service provider:

Figure 13.1 – Key aspects of a decentralized cloud-native app

Figure 13.1 – Key aspects of a decentralized cloud-native app

We put decentralization at the core to provide the central architectural design decision to distribute control and management across a blockchain network, rather than having it centralized. Around the decentralized nature of the solution, the cloud service provider adds the following capabilities:

  • Scalability: Utilizing AWS’s cloud infrastructure allows the marketplace to scale resources up or down as needed
  • Security: Using blockchain for transaction validation and AWS services for secure cloud operations
  • Transparency: All...

Setting up the blockchain network on AWS

Setting up the essential AWS services is crucial for the infrastructure of our decentralized marketplace.

Setting up Amazon EC2

Follow these steps to set up Amazon EC2 services:

  1. Open the AWS management console at https://aws.amazon.com/console/ and navigate to EC2 from the list of services. Click on Launch instance to create a new EC2 instance:
Figure 13.3 – Launching a new EC2 instance from the AWS management console

Figure 13.3 – Launching a new EC2 instance from the AWS management console

  1. Select an Amazon Machine Image (AMI) according to your needs. For a basic setup, you can choose an Ubuntu server:
Figure 13.4 – Selecting an Ubuntu server AMI

Figure 13.4 – Selecting an Ubuntu server AMI

  1. Choose an existing key pair, which is required to log into the VM, or create a new one and download it:
Figure 13.5 – Selecting or creating a key pair for logging in

Figure 13.5 – Selecting or creating a key pair for logging in

  1. Choose the instance type (for example, t2.micro for testing...

Creating the decentralized marketplace application

Creating a frontend interface to interact with your deployed smart contract on the blockchain involves using web development frameworks and libraries that can communicate with Ethereum nodes. For this example, we’ll use React and web3.js.

The prerequisites for executing the code in this section include having Node.js and npm installed, a smart contract deployed on the Ethereum node that we set up on AWS in the previous section, and MetaMask or another web3 wallet installed in our browser. Some basic familiarity with the React framework will also help us understand the code in detail.

The following steps will help us install the frontend of the marketplace application:

  1. First, create a new React app by running the following bash command:
    npx create-react-app my-decentralized-marketplace

    Then, navigate to the project folder:

    cd my-decentralized-marketplace
  2. Install the web3.js library so that you can interact with...

Deploying the decentralized marketplace on AWS

The final step to complete this lab is to deploy the marketplace solution to the AWS services that we provisioned at the beginning. Deploying and especially automating the deployment of smart contracts can be challenging. For tools and best practices in deploying smart contracts, please refer to Chapter 3 of this book.

Deploying a smart contract to a blockchain network is a key step in building a decentralized marketplace. The following instructions focus on the Ethereum blockchain, utilizing Solidity for the smart contract and Truffle as the development environment:

  1. Install Truffle globally using npm:
    npm install -g truffle
  2. Create a new directory for the project and navigate to it:
    mkdir MyDecentralizedMarketplace
    cd MyDecentralizedMarketplace
  3. Initialize the Truffle project:
    truffle init
  4. Create a new Solidity file under the contracts directory in the Truffle project:
    touch contracts/Marketplace.sol

    Edit Marketplace.sol...

Summary

In this hands-on lab, we explored the key components of building and scaling a decentralized marketplace using AWS and blockchain technology. The lab started with setting up essential AWS services, including EC2 for hosting blockchain nodes, RDS for off-chain data storage, and S3 for storing large files. We then dived into deploying a smart contract on an Ethereum blockchain network.

Next, we developed a frontend interface using React.js and web3.js to interact with the deployed smart contract. The frontend allows for the addition and retrieval of products in the decentralized marketplace.

Ready for another hands-on lab? In the next chapter, we’ll develop a decentralized voting application on Azure.

Further reading

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Developing Blockchain Solutions in the Cloud
Published in: Apr 2024Publisher: PacktISBN-13: 9781837630172
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime

Authors (2)

author image
Stefano Tempesta

Stefano Tempesta is a technologist working at the crossroads of Web2 and Web3 to make the internet a more accessible, meaningful, and inclusive space. Stefano is an ambassador of the use of AI and blockchain technology for good purposes. A former advisor to the Department of Industry and Science, Australia, on the National Blockchain Roadmap, he is cofounder of Aetlas, a decentralized climate action and sustainability network with a mission to source verified carbon units for liquidity and carbon asset monetization. A passionate traveler, a poor musician, and an avid learner of new technologies and (programming) languages, Stefano holds three citizenships and speaks fluent English, Italian, and terrible Ukrainian.
Read more about Stefano Tempesta

author image
Michael John Peña

Michael John Peña, an engineer and Microsoft MVP, excels in tech innovation and leadership. As a data partner at Playtime Solutions, he spearheads projects utilizing Azure, big data, and AI, enhancing data-driven decision-making. With roles ranging from CTO to software engineer, MJ's expertise covers web/app development, cloud computing, blockchain, and IoT. His commitment to lifelong learning and sharing knowledge—underscored by his work with start-ups and as a technical advisor—drives industry advancements in finance, construction, and more. MJ values inclusivity and actively fosters diverse, collaborative environments.
Read more about Michael John Peña