Coder Social home page Coder Social logo

blockchain-time-service's Introduction

Blockchain Time Service

Overview

This project demonstrates a seamless integration of Ethereum blockchain payments with a cloud-hosted microservice, providing the current time. Users interact with the service using blockchain for payment.

Specifications

  • The microservice, hosted on the AWS cloud, echoes back the current time.
  • Payment is handled through a smart contract on the Ethereum Sepolia testnet.
  • The service costs one cent USDC per usage, charged via the smart contract.

System Architecture

The system's architecture comprises several key components:

  • Web Browser (Client): Allows the user to access the web UI to interact with the service.
  • MetaMask: Facilitates Ethereum transactions and interacts with the user's wallet.
  • AWS API Gateway (Public): A managed service that handles the HTTP requests.
  • AWS Lambda (Time Microservice): Executes the function to fetch and return the current time.
  • Amazon S3 (Webpage Hosting): Hosts the web UI, allowing users to initiate service requests.
  • Ethereum Sepolia Testnet (Smart Contract): Processes payments and handles the transaction logic.

Architecture Diagram

Architecture Diagram

Flow of Control

Users make a request through the UI to view the current time. They authorize the payment via MetaMask, which prepares to interact with the smart contract. Upon payment authorization, the UI sends the request to the AWS API Gateway. The API Gateway forwards the request to the Lambda function. Lambda processes the request, obtaining the current time. In parallel, the smart contract on the Sepolia testnet manages the payment transaction. The Lambda function sends the time data back through the API Gateway. ...

Deliverables

  • Architecture Diagram: Visual representation of the system's components and their interconnectivity.
  • Microservice: AWS Lambda function to provide the current time.
  • User Interface: Web UI hosted on Amazon S3 for service interaction.
  • Payment Smart Contract: Deployed on Ethereum's Sepolia testnet.

Smart Contract Overview

The smart contract TimeCollector is deployed on the Ethereum Sepolia testnet and interacts with USDC tokens.

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract TimeCollector {
    event TimeRequested(address indexed sender, uint256 timestamp);
    IERC20 public usdc;

    uint256 public constant FEE = 10000; // 1 cent in USDC smallest units

    constructor(address _usdcAddress) {
        usdc = IERC20(_usdcAddress);
    }

    function collectTime() public {
        require(usdc.transferFrom(msg.sender, address(this), FEE), "Payment failed");
        emit TimeRequested(msg.sender, block.timestamp);
    }
}
  • Token Interaction: It interacts with USDC tokens, a stablecoin pegged to the US dollar, using the ERC-20 standard (IERC20). This interaction ensures a stable and predictable transaction cost.

  • Functionality:

    • Collect Fee: Users pay a fee of one cent in USDC to retrieve the current time. This fee is automatically transferred from the user's wallet to the contract.
    • Log Transactions: Each successful payment triggers an event, logging the requester's address and the time of the transaction, enhancing transparency and auditability.

Access Requirements

To access and use the time service application, you will need:

  • MetaMask: A browser extension or mobile app connected to the Ethereum Sepolia testnet.
  • USDC Tokens: A balance of USDC tokens on the Sepolia testnet in your MetaMask wallet to cover the service fees.
  • Web Browser: A compatible web browser like Chrome, Firefox, or Brave with the MetaMask extension installed.

Getting Started

blockchain-time-service's People

Contributors

akhilesharora avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.