Skip to content

moveaxlab/HeD-smart-contract

Repository files navigation

PoC Blockchain

This repository contains a proof-of-concept (PoC) implementation of the blockchain module intended for integration into the Health-e-Data architecture, using Amoy network, a Polygon testnet.

HardHat

This project utilizes HardHat as the development environment for compiling, testing, and deploying smart contracts.

Smart Contracts

The core logic of this PoC is located in the contracts/ directory, which contains Solidity (.sol) files implementing the smart contract functionality.

Blockchain deployment and transactions

Interacting with the blockchain involves deploying smart contracts and executing transactions. This section provides the necessary steps for configuring your environment and writing data to the blockchain.

Configuration

  1. Make sure you have mise installed

  2. Install dev environment dependencies

    mise install
  3. Install node modules

    npm install
  4. Retrive the following informations:

    1. Get an API Key for Polygon network on Metamask.io, if you don't have one already follow the steps in this guide to create it

    2. Get a PolygonScan Api Key following this guideline

      This step can be skipped if you do not intend to verify the contract via CLI)

    3. Get the private key of your polygon account. Thi account will be used for deploying the smart contract and setting new policies.

      Make sure the account has enough MATIC on the Amoy network; otherwise, use a faucet to get some.

  5. Create a file .mise.local.toml at project root level with this structure.

    [env]
    INFURA_API_KEY = "<API Key from  Metamask.io (1)>"
    POLYGONSCAN_API_KEY "<API Key from PolygonScan (2) >
    TESTNET_PRIVATE_KEY = "<Private key of your account (3)>"
    

    Important: This file contains sensitive information. Do not share or commit it to version control.

Deployment

To deploy your contract to the blockchain, run the following command:

npx hardhat run scripts/deploy.ts --network amoy

Upon successful deployment, the console will display the address of the deployed contract. Store this address in your .mise.local.toml file as follows:

HED_CONTRACT_ADDRESS = "<Deployed contract address>"

Contract Verification

To ensure transparency and facilitate interaction, you can verify the deployed smart contract using either PolygonScan's web interface or the Hardhat command-line tool.

Benefits of Verification:

  • Enhanced Transparency: Verification allows anyone to inspect the contract's source code, fostering trust and accountability.
  • Simplified Interaction: Verified contracts on PolygonScan enable users to interact with the smart contract directly through the web interface, leveraging the Application Binary Interface (ABI).
  • Gas-Free Read Operations: Users can execute read-only functions (view/pure methods) without incurring gas fees or requiring a blockchain account.

Using PolygonScan (GUI):

  • Navigate to the contract address on Amoy PolygonScan.
  • Follow the on-screen instructions to verify the contract.

Using Hardhat (Command-line):

Execute the following command, replacing YOUR_CONTRACT_ADDRESS with the deployed contract address:

npx hardhat verify --network amoy YOUR_CONTRACT_ADDRESS

Setting a Policy

To set a new policy on the blockchain, execute the following command and follow the on-screen instructions:

npx hardhat run scripts/setPolicy.ts --network amoy

Testing

Each smart contract file in contracts/ should have a corresponding test file in the test/ directory, ensuring comprehensive test coverage.

To run all tests using HardHat, execute:

npx hardhat test

For more detailed information, including test coverage, run:

npx hardhat coverage

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •