This section demonstrates advanced usage patterns for the consent-based data provenance system, including meta-transactions, delegated consent, batch operations, and role-based access control.
- Developers: Implement production-ready patterns
- Architects: Design scalable consent systems
- Business Operators: Understand advanced capabilities
Gasless consent operations using signatures.
npx hardhat run examples/07-advanced-patterns/01-meta-transactions.ts --network localhostScenario:
Gasless consent flow:
├── User signs consent message off-chain
├── Relayer submits transaction
├── User doesn't need ETH for gas
└── Consent recorded on-chain
Demonstrates:
- EIP-712 typed data signing
- Signature-based consent
- Relayer pattern for gas abstraction
Power of attorney and guardianship patterns.
npx hardhat run examples/07-advanced-patterns/02-delegated-consent.ts --network localhostScenario:
Healthcare delegation:
├── Patient authorizes guardian
├── Guardian consents on patient's behalf
├── Consent linked to patient
└── Delegation can be revoked
Demonstrates:
- ConsentProxy for delegation
- Guardian/POA consent
- Delegation management
Bulk consent and data operations.
npx hardhat run examples/07-advanced-patterns/03-batch-operations.ts --network localhostScenario:
Bulk consent management:
├── Give multiple consents at once
├── Revoke multiple consents
├── Validate multiple receipts
└── Register multiple data records
Demonstrates:
- KantaraConsentReceipt batch functions
- Gas-efficient bulk operations
- Transaction batching patterns
Role-based access control for consent systems.
npx hardhat run examples/07-advanced-patterns/04-rbac-administration.ts --network localhostScenario:
Organization roles:
├── Admin manages roles
├── Auditors can query
├── Operators can record
└── Users manage own data
Demonstrates:
- ConsentAuditLog admin functions
- Authorized recorder management
- Role-based permissions
Granular data access control.
npx hardhat run examples/07-advanced-patterns/05-access-level-management.ts --network localhostScenario:
Access levels:
├── Read: View data only
├── Transform: Can process data
├── Full: Complete control
└── Time-bounded access
Demonstrates:
- DataAccessControl contract
- Tiered access levels
- Access expiration
┌─────────────────────────────────────────────────────────────────┐
│ Advanced Patterns │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ META-TRANSACTIONS │ │
│ │ User ──▶ Sign Message ──▶ Relayer ──▶ Blockchain │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ DELEGATED CONSENT │ │
│ │ Principal ──▶ Authorize ──▶ Delegate ──▶ Act on Behalf │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ BATCH OPERATIONS │ │
│ │ Multiple Items ──▶ Single Transaction ──▶ Atomic Result │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ ACCESS CONTROL │ │
│ │ Owner ──▶ Grant ──▶ Grantee ──▶ Time-bounded Access │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
| Pattern | Contract | Key Functions |
|---|---|---|
| Meta-transactions | (Off-chain signing) | EIP-712 signatures |
| Delegated consent | ConsentProxy | authorizeDelegate, delegatedConsent |
| Batch operations | KantaraConsentReceipt | batchRevokeConsent, batchIsConsentValid |
| RBAC | ConsentAuditLog | setAuthorizedRecorder |
| Access levels | DataAccessControl | grantAccess, checkAccess |
| Level | Value | Capabilities |
|---|---|---|
| None | 0 | No access |
| Read | 1 | View data only |
| Transform | 2 | Read + process/transform |
| Full | 3 | Complete control |
- Delegated consent requires explicit authorization
- Meta-transaction signatures should include nonces
- Batch operations have size limits for gas
- Access grants should have reasonable expiration
- RBAC admin functions require careful key management
After completing these examples, explore:
- Compliance & Audit - Regulatory patterns
- Integration Patterns - System integration