This section introduces the basic concepts of consent management using the ConsentReceipt contract.
- End Users: Understand how consent works from a user perspective
- Developers: Learn the fundamental API patterns
The simplest consent flow: give consent for a purpose and verify it.
npx hardhat run examples/01-getting-started/01-basic-consent.ts --network localhostDemonstrates:
- Deploying ConsentReceipt contract
- Giving consent for a purpose
- Checking consent status
- Viewing consent details
Time-limited consent that automatically becomes invalid after expiration.
npx hardhat run examples/01-getting-started/02-consent-with-expiry.ts --network localhostDemonstrates:
- Setting expiration time on consent
- Verifying consent validity over time
- Understanding blockchain timestamps
How users can revoke their consent at any time.
npx hardhat run examples/01-getting-started/03-revoke-consent.ts --network localhostDemonstrates:
- Revoking consent by index
- Consent status after revocation
- Maintaining consent history
The main orchestrator that ties consent and data provenance together.
npx hardhat run examples/01-getting-started/04-integrated-system.ts --network localhostDemonstrates:
- IntegratedConsentProvenanceSystem contract
- Consent-verified data operations
- Automatic consent checking before data access
- Data restriction on consent revocation
- Complete audit trail with consent linkage
Each consent record contains:
struct Consent {
address user; // Who gave consent
string purpose; // What they consented to
uint256 timestamp; // When consent was given
uint256 expiryTime; // When it expires (0 = never)
bool isValid; // Current validity status
}A consent is considered valid when:
isValidistrue(not revoked)expiryTimeis0ORexpiryTime > block.timestamp
Purposes are free-form strings. Common patterns:
"email_marketing"- Marketing communications"analytics"- Website/app analytics"data_sharing"- Third-party data sharing"medical_treatment"- Healthcare consent
// Give consent (no expiry)
await consentReceipt.connect(user)["giveConsent(string)"]("purpose");
// Give consent (with expiry)
await consentReceipt.connect(user)["giveConsent(string,uint256)"]("purpose", expiryTime);
// Check if consent is valid
const hasConsent = await consentReceipt.getConsentStatus(userAddress, "purpose");
// Revoke consent by index
await consentReceipt.connect(user).revokeConsent(consentIndex);
// Get all user's consents
const consents = await consentReceipt.getUserConsents(userAddress);
// Get consent count
const count = await consentReceipt.getUserConsentsCount(userAddress);After completing these examples, explore:
- Healthcare - Multi-purpose consent with data provenance
- Marketing - Cookie consent and preference management
- Advanced Patterns - Batch operations and meta-transactions