Skip to content

Latest commit

 

History

History
163 lines (124 loc) · 4.9 KB

File metadata and controls

163 lines (124 loc) · 4.9 KB

VeriChain Setup Guide

VeriChain is a blockchain-based pharmaceutical supply chain tracking system using Hyperledger Fabric, Node.js, and React.

Prerequisites

  • OS: Linux (Ubuntu/WSL2 recommended) or macOS
  • Docker: v20.10+ (with Docker Compose v2.x or v1.29+)
  • Node.js: v16.x or v18.x (v20+ might have OpenSSL issues with older Fabric SDKs)
  • Hyperledger Fabric Binaries: v2.5.x (installed in ./bin)

1. Network Setup (Hyperledger Fabric)

The network consists of 4 Organizations (Pharma1, Pharma2, Distributor, Retailer) and 1 Orderer.

  1. Navigate to the project root:

    cd verichain
  2. Start the Network: This script will bring down any existing network, generate crypto material, create the channel verichain-channel, and deploy the chaincode.

    ./setup_verichain.sh

    Note: This might take a few minutes.

  3. Verify Chaincode Deployment: Ensure the chaincode basic is deployed to verichain-channel.

    export PATH=$PWD/bin:$PATH
    peer lifecycle chaincode querycommitted --channelID verichain-channel --name basic

2. Database Setup (PostgreSQL)

VeriChain uses PostgreSQL for off-chain data (inventory, ZK proofs) and caching.

  1. Start PostgreSQL:

    docker-compose up -d postgres

    Port: 5433 (mapped to container 5432) User: verichain Password: verichain_secret Database: verichain

  2. Verify Schema: The database initializes with verichain-api/src/db/schema.sql.

3. Backend API Setup

The Node.js API interacts with the Fabric network and PostgreSQL.

  1. Navigate to API directory:

    cd verichain-api
  2. Install Dependencies:

    npm install
  3. Restore Identities (Important for Fresh Network): If you restarted the network, you must import the new admin/user certificates into the wallet.

    node restore_identities.js
  4. Start the Server:

    npm start

    URL: http://localhost:3000

4. Frontend Setup

The React frontend provides the user interface.

  1. Navigate to Frontend directory:

    cd verichain-frontend
  2. Install Dependencies:

    npm install
  3. Start the Development Server:

    npm run dev

    URL: http://localhost:5173

5. Usage Flow

  1. Login:

    • Pharma: Use the "Pharma 1" demo button.
    • Distributor: Use the "Distributor" demo button.
    • Retailer: Use the "Retailer" demo button.
  2. Create Asset (Pharma):

    • Go to "Create Asset".
    • Enter details (e.g., ID: VAX-001, Drug: Covid-19 Vaccine).
    • Click "Create Asset".
  3. Simulate Transit (Pharma/Distributor):

    • Go to "Dashboard".
    • Click "Simulate Transit" on the asset.
    • This generates a ZK Proof (mocked/simulated) and transfers ownership to Distributor.
  4. Accept Shipment (Retailer):

    • Login as Retailer.
    • Go to "Inventory".
    • Click "Accept Shipment" for pending assets.
    • This transfers ownership to Retailer and updates status to STOCKED.
  5. Query Ledger:

    • Use the script to see the full history of an asset:
    ./query_ledger.sh VAX-001

6. Shardeum Public Notary Bridge

VeriChain includes a bridge to notarize ZK-proofs on the Shardeum Testnet.

Setup

  1. Deploy Contract:

    • Open Remix IDE.
    • Create a new file Notary.sol and paste the content from shardeum/Notary.sol.
    • Compile and Deploy to Shardeum Sphinx 1.X (Injected Provider - MetaMask).
    • Copy the Deployed Contract Address.
  2. Configure API:

    • Open verichain-api/.env.
    • Add your Private Key (with test SHM) and the Contract Address:
      SHARDEUM_PRIVATE_KEY=your_private_key_here
      SHARDEUM_CONTRACT_ADDRESS=0x...
    • Restart the API: npm start.

Usage

  • When you generate a ZK Proof (as Distributor), click the "Notarize to Shardeum" button (if implemented in UI) or call the API endpoint: POST /api/transit/notarize with { "assetId": "...", "proofHash": "..." }.
  • The system will return a Transaction Hash and a QR Code URL pointing to the Shardeum Explorer.

Troubleshooting

  • "Peer endorsements do not match":

    • This usually means the chaincode is non-deterministic. We fixed this by using transaction timestamps. Redeploy chaincode if this recurs.
  • "Connect ECONNREFUSED 127.0.0.1:5433":

    • PostgreSQL is not running. Run docker-compose up -d postgres.
  • "User not found in wallet":

    • Run node restore_identities.js in verichain-api to restore demo users.
  • "Collection not found":

    • Chaincode was deployed without collections_config.json. Redeploy with the -cccg flag.