Smart Contracts

Detailed documentation of ConsentManager and RevenueSplitter contracts deployed on Hedera EVM.

ConsentManager

The ConsentManager contract provides an on-chain registry of patient consent records. It stores anonymous patient IDs, HCS topic IDs, data hashes, and timestamps for immutable consent tracking.

ConsentManager Functions

recordConsent()

Records a new consent entry

1function recordConsent(
2    string memory anonymousId,
3    string memory hcsTopicId,
4    bytes32 dataHash
5) public

Parameters:

  • anonymousId: Anonymous patient identifier (e.g., "PID-001")
  • hcsTopicId: Hedera Consensus Service topic ID
  • dataHash: Cryptographic hash of the anonymized dataset

revokeConsent()

Revokes a previously recorded consent

1function revokeConsent(
2    string memory anonymousId,
3    bytes32 dataHash
4) public

Marks a consent as revoked, preventing future data access for that record.

isConsentValid()

Checks if a consent is valid

1function isConsentValid(
2    string memory anonymousId,
3    bytes32 dataHash
4) public view returns (bool)

Returns true if consent exists and is not revoked, false otherwise.

getConsentByAnonymousId()

Retrieves consent information

1function getConsentByAnonymousId(
2    string memory anonymousId
3) public view returns (Consent memory)

Returns the complete consent record including HCS topic ID, data hash, timestamp, and status.

RevenueSplitter

The RevenueSplitter contract automatically distributes revenue from dataset purchases according to a fixed split: 60% to patients, 25% to hospitals, and 15% to the platform.

RevenueSplitter Functions

receive()

Automatically distributes received HBAR

1receive() external payable {
2    // Automatically splits incoming HBAR:
3    // 60% to patient accounts
4    // 25% to hospital accounts
5    // 15% to platform account
6}

This function is called automatically when HBAR is sent to the contract. It distributes the payment according to the configured split percentages.

distributeRevenueTo()

Manually distribute revenue to specific recipients

1function distributeRevenueTo(
2    address patientAccount,
3    address hospitalAccount,
4    uint256 totalAmount
5) public

Allows manual distribution with specific account addresses. Calculates split amounts based on configured percentages.

getSplitPercentages()

Returns the current revenue split configuration

1function getSplitPercentages() 
2    public 
3    view 
4    returns (
5        uint256 patientPercent,
6        uint256 hospitalPercent,
7        uint256 platformPercent
8    )

Returns the configured percentages: 60% patient, 25% hospital, 15% platform.

Revenue Distribution Flow

How It Works

  1. Researcher purchases dataset and sends HBAR to RevenueSplitter contract
  2. Contract receives payment via receive() function
  3. Contract calculates split: 60% patient, 25% hospital, 15% platform
  4. HBAR is transferred to respective Hedera accounts (0.0.xxxxx)
  5. All transactions are recorded on Hedera and verifiable on HashScan
60%
Patient
25%
Hospital
15%
Platform

Contract Deployment

Hedera EVM

Both contracts are deployed on Hedera EVM, which provides:

  • Low gas costs compared to Ethereum mainnet
  • Fast transaction finality
  • EVM compatibility for standard Solidity development
  • Integration with Hedera native services (HCS, Accounts, HBAR)

Verification

Contract addresses and transactions can be verified on HashScan, providing transparency and auditability for all consent records and revenue distributions.