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) publicParameters:
anonymousId: Anonymous patient identifier (e.g., "PID-001")hcsTopicId: Hedera Consensus Service topic IDdataHash: Cryptographic hash of the anonymized dataset
revokeConsent()
Revokes a previously recorded consent
1function revokeConsent(
2 string memory anonymousId,
3 bytes32 dataHash
4) publicMarks 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) publicAllows 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
- Researcher purchases dataset and sends HBAR to RevenueSplitter contract
- Contract receives payment via
receive()function - Contract calculates split: 60% patient, 25% hospital, 15% platform
- HBAR is transferred to respective Hedera accounts (0.0.xxxxx)
- All transactions are recorded on Hedera and verifiable on HashScan
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.