Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Solution Thumbnail

Creating a Point-of-Sale Application with the Algorand Blockchain

Overview

Today, consumers and retailers are looking for fast, efficient, secure, and convenient payment solutions.

Credit cards currently dominate point-of-sale. They charge high fees (2% - 4%), promote consumer debt, and require a settlement period of up to 30 days. Credit cards are also subject to fraud, totaling over $24 Billion worldwide in 2018. Consumers and retailers are ready for a better alternative.

Algorand blockchain technology can significantly reduce costs, settlement time, and fraud. With Algorand, transaction fees are less than $0.001/transaction, are settled immediately (~5 seconds), and are stored permanently on the blockchain. Algorand’s support for assets enables the use of local currencies for exchange. All of these factors will improve customer satisfaction.

In this solutions article, we show how to use Algorand’s blockchain to create an alternative payment solution for processing retail transactions. The solution demonstrates a point-of-sale application and a signing wallet. We also introduce the Transaction Gateway, a framework designed to help streamline application development using the Algorand blockchain.

Development Challenges

In the creation of a point-of-sale application, there are challenges:

Monetization

As an application developer, how can I monetize the point-of-sale application?

Transaction Signing

How can I orchestrate the signing of transactions in a way that protects the consumer’s signing key? How can multi-party and multi-signature transactions be processed when there are multiple signers required?

Smart Contracts

Will the application require a smart contract, and if so, how will this be constructed and secured? How do we explain it to consumers?

Limited Transaction Storage

Blockchain transaction storage is limited; for Algorand, the limit is 1KB. However, many business transactions include a receipt, invoice, bill, or other forms of agreement that exceeds this limit. How can the agreement information be included with the purchase, so that it is clear to consumers what they agree to when signing transactions?

Marketing

How can I capture market share from existing solutions? Payment systems based on credit cards originated in the 1950s. Businesses vested in these legacy systems will be disinclined to change unless provided a practical and rewarding alternative.

Solution

To address these challenges, we introduce the concept of a Transaction Gateway to act as an intermediary between the point-of-sale application and the Algorand blockchain. The Transaction Gateway will coordinate the various components that work together to complete the transaction workflow.

Components

There are five key components:

The point-of-sale application is specific to the retail payment use case; the other parts are reusable. The following diagram illustrates these components:


PoS Component Diagram

Point-of-Sale Application

For each purchase, the point-of-sale application creates a transaction and submits it to the Transaction Gateway, which manages the signing process and notifies the point-of-sale application when the transaction has been successfully committed to the blockchain.

Online and physical PoS systems, both fixed and mobile, can be supported. Algorand’s Multi-Transfer transactions support multiple payers and receivers within a single transaction. For example, multiple diners can split a restaurant bill, sending a tip directly to the waiter, paying taxes, rating the experience, and receiving customer appreciation rewards (asset) as part of the payment transaction.

Transaction Gateway

The Transaction Gateway coordinates the interaction between the business application and the Algorand blockchain. The point-of-sale app sends unsigned transactions to the Transaction Gateway, which then forwards the transactions to the appropriate wallets for signing. After signing the transaction, the wallet sends the signed transaction back to the Transaction Gateway, which commits it to the Algorand blockchain. The Transaction Gateway notifies the point-of-sale application when the payment is complete.

The Transaction Gateway provides a REST API for interaction with the point-of-sale Application and the Signing Wallet. The following defines the Transaction Gateway interface.

TransactionGatewayInterface {
   submitUnsignedTransaction(Transaction):void
   retrieveUnsignedTransactionsForAccount(accountAddress):List<Transaction>
   submitSignedTransaction(Transaction):void
} 

The following diagram shows how the Transaction Gateway supports multiple application types in addition to point-of-sale.


Transaction Gateway

Signing Wallet

The Signing Wallet is a client application used by consumers to manage and protect their Algorand account and to sign transactions received from the Transaction Gateway. The Signing Wallet can be a mobile app, web app, or desktop application. When the Signing Wallet receives a transaction, it notifies the user and displays the details to the user, including the receipt stored off-chain, and then prompts the user to either accept or reject the transaction. If the user agrees, then the wallet will sign the transaction and return the signed transaction to the Transaction Gateway.

Signing Wallets can also be implemented as automated signing services, or as custom applications that provide other business-specific capabilities in addition to transaction signing.

Algorand Blockchain

The Algorand blockchain provides a fast and efficient payment platform. It features support for Assets allowing support for local currencies. It also supports multi-party transactions and multi-signature accounts, used when multiple signers are required. The Algorand blockchain supports real-time payment, processing transactions within 5 seconds, with a throughput of 1,000 transactions/second. This efficiency results in nominal transaction fees, currently less than $0.001/transaction.

Off-Chain Storage

Off-chain storage provides capacity for transaction-related information that won’t fit within the note field of a transaction. In payment and other types of transactions, there is often a receipt, bill, invoice, manifest, or some kind of agreement that provides information about the purchase.

Off-chain storage can be supported in different ways, for example, using commercial file systems (e.g., Amazon S3) or open-source alternatives.

The Interplanetary File System (IPFS) is an open-source solution that is well suited for the off-chain storage of transaction-related information. The IPFS is a decentralized file storage system that uses a cryptographic hash of the content as the address, which makes the content immutable.

The note field includes the URL of the content stored off-chain. Optionally, data encryption protects the privacy of the data.

Transaction Flow

The following diagram describes the message flow for creating and processing a transaction.

Activity Diagram

The business application generates transaction(s) and sends it to Transaction Gateway. The Transaction Gateway then forwards the transaction to the appropriate wallet for signing. The wallet displays the transaction details to the consumer. If the consumer accepts that transaction, then the wallet signs the transaction and returns the signed transaction to the Transaction Gateway. The Transaction Gateway then sends the transaction to the Algorand blockchain and notifies the application that the purchase is complete once confirmed.

Example Point-of-Sale Implementation

In this example, we provide a point-of-sale application and wallet that communicate via the Transaction Gateway. You can find the source code here: https://github.com/algorand/code-samples/tree/master/point-of-sale

Point-of-Sale

The point-of-sale application captures the purchase details and generates an unsigned transaction and forwards it to the Transaction Gateway.


Point of Sale

Signing Wallet

The signing wallet retrieves the unsigned transaction from the Transaction Gateway and presents it to the consumer who approves the transaction. Once approved, the wallet signs the transaction and sends the signed transaction to the Transaction Gateway. The following screenshot shows the Wallet UI.


Signing Wallet

The receipt details are stored off-chain in IPFS. The transaction’s note field contains the IPFS URL. The following screenshot shows the transaction receipt stored in IPFS.


IPFS

Summary

In this article, we have shown how to construct a point-of-sale application using reusable components, including the Algorand blockchain, Transaction Gateway, signing wallet, and an off-chain storage system.

The resulting system significantly reduces the cost of transaction processing, through lower transaction fees and reduced fraud. The consumer experience is improved with an easy-to-use transaction signing platform (wallet) that can work with a broad range of business applications. Transaction processing is transparent, and attached receipts or other types of agreements are familiar and intuitive. The customer’s signing credentials remain secure because they never leave the signing wallet. Algorand’s fast transaction processing supports real-time payment confirmation.

The Transaction Gateway facilitates integration with the Algorand blockchain, allowing the business application development team to focus on delivering business value. Convenient support for multi-transfer transactions enables monetization for the point-of-sale application provider. No reliance on smart contracts lowers the barrier to entry for software development organizations and can accelerate customer adoption through improved transparency and trust.

Existing and new point-of-sale systems can be integrated with the Algorand blockchain via the Transaction Gateway, providing a secure, fast, convenient, and cost-effective payment system.