# Blockchain-Based Loyalty Management System
## 3 Proposed loyalty Management System
### System Architecture  
After taking into consideration all factors mentioned previously, it is essential to define a detailed architecture with all the different software components, the interaction with external services, and the communication protocols. The architecture is composed of three major modules: (i) the mobile application the users will interact with; (ii) external services for facilitating user integration with blockchain and providing a set of required features, namely InterPlanetary File System (IPFS), Torus Web3 Auth, Ramp Exchange, and Openzeppelin; and (iii) smart contracts that contain the system's business logic. Figure 3 represents the system architecture. As the system allows for different loyalty mechanisms, to facilitate the entire loyalty program management process, each smart contract represents a specific loyalty mechanism. Since numerous retailers with a specific loyalty mechanism can exist, each smart contract will inherit the ERC-1155 interface [29] through the contract available through Openzeppelin. ERC-1155 is a token standard interface that facilitates the smart contract representing multiple tokens simultaneously, and includes management functions that efficiently help in reducing the fees. This interface, along with the already pre-built ERC-1155 contract, simplifies the whole management process and diminishes the effort needed to create smart contracts from scratch. Furthermore, since ERC-1155 allows multiple tokens to be managed within a single contract, the proposed loyalty management system can significantly reduce the number of smart contracts required, unlike current systems that require separate ERC-20 contracts for each token. Given the large number of tokens involved in our system, the use of ERC-1155 thus results in a more efficient and scalable solution that requires a minimum number of contracts: a single smart contract is required for delegating calls and storing data unrelated to loyalty programs, and a separate smart contract inheriting the ERC-1155 contract is required for each loyalty mechanism. The proposed loyalty system includes an intelligent contract manager to simplify blockchain calls, which is responsible for receiving transaction requests and delegating their execution to a contract running a specific loyalty mechanic. The manager is also responsible for storing all generic data, such as which retailers are defined in the system, customer subscriptions, and smart contract addresses for loyalty mechanics. Through this approach, calls to interact and obtain information from blockchain are simplified. Furthermore, in order to prevent any unauthorized data manipulation, all data are directly associated with the user's unique wallet address. This approach guarantees that only the users themselves can modify their data, thus preventing any malicious user from tampering with other users' information. In order to streamline the development of smart contracts for each mechanism and store them in the loyalty manager component of the proposed system, a loyalty mechanism interface was created (see Figure 3). This interface defines four methods that each mechanism contract must implement to properly define its behavior. The loyalty manager stores all the mechanism contracts with a map, upon which the keys are an \"enum\" and the values are references to the loyalty mechanism interface type that corresponds to contracts responsible for delegating the received calls to the corresponding contracts. Torus Web3 Auth is a pluggable authentication infrastructure for Web3 wallets and applications. It provides seamless onboarding by providing web 2.0 login flows, such as Facebook, Gmail, and Twitter. Despite the fact that the user is abstracted from wallet creation, he/she is always in control of ownership.