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.
This project utilizes HardHat as the development environment for compiling, testing, and deploying smart contracts.
The core logic of this PoC is located in the contracts/ directory, which contains Solidity (.sol) files implementing the smart contract functionality.
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.
- 
Make sure you have mise installed 
- 
Install dev environment dependencies mise install 
- 
Install node modules npm install 
- 
Retrive the following informations: - 
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 
- 
Get a PolygonScan Api Key following this guideline This step can be skipped if you do not intend to verify the contract via CLI) 
- 
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. 
 
- 
- 
Create a file .mise.local.tomlat 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. 
To deploy your contract to the blockchain, run the following command:
npx hardhat run scripts/deploy.ts --network amoyUpon 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>"
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.
- Navigate to the contract address on Amoy PolygonScan.
- Follow the on-screen instructions to verify the contract.
Execute the following command, replacing YOUR_CONTRACT_ADDRESS with the deployed contract address:
npx hardhat verify --network amoy YOUR_CONTRACT_ADDRESSTo set a new policy on the blockchain, execute the following command and follow the on-screen instructions:
npx hardhat run scripts/setPolicy.ts --network amoyEach 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 testFor more detailed information, including test coverage, run:
npx hardhat coverage