A decentralized Clarity smart contract for verifying agricultural seed authenticity on the Stacks blockchain. This system enables producers to register seeds and authorized verifiers to certify their authenticity, creating an immutable audit trail for the agricultural supply chain.
- Seed Registration: Producers can register seeds with comprehensive metadata including genetic hash, batch numbers, and origin information
- Verification System: Authorized verifiers can certify or revoke seed authenticity
- Ownership Transfer: Seeds can be transferred between parties while maintaining verification history
- Audit Trail: Complete verification history tracking with timestamps and notes
- Expiry Management: Automatic validation of seed expiry dates
- Role-Based Access: Three distinct roles (Contract Owner, Verifiers, Producers)
- Input Validation: All inputs validated before processing to prevent malicious data
- Authorization Checks: Functions restricted to appropriate roles
- Immutable History: Verification records cannot be altered once created
- Deployer of the contract
- Can add/remove authorized verifiers
- Can register new producers
- Can update verification fees
- Automatically registered as both verifier and producer
- Can verify seed authenticity
- Can revoke existing verifications
- Access to verification functions only
- Can register new seed batches
- Can transfer seed ownership
- Must be registered by contract owner
Adds a new authorized verifier to the system.
- Caller: Contract owner only
- Parameters:
verifier- Principal address to authorize - Returns:
(ok true)on success
Removes an authorized verifier from the system.
- Caller: Contract owner only
- Parameters:
verifier- Principal address to deauthorize - Returns:
(ok true)on success
Registers a new seed producer.
- Caller: Contract owner only
- Parameters:
producer- Principal address to register - Returns:
(ok true)on success
Registers a new seed batch with full metadata.
- Caller: Registered producers only
- Parameters:
seed-type(string-ascii 50): Type of seed (e.g., "Maize", "Wheat")batch-number(string-ascii 50): Unique batch identifierproduction-date(uint): Block height of productionexpiry-date(uint): Block height when seed expiresquantity(uint): Number of seeds in batchgenetic-hash(buff 32): 32-byte genetic fingerprintorigin(string-ascii 100): Geographic origin
- Returns:
(ok seed-id)- Unique seed identifier - Validations:
- Producer must be registered
- All strings must be non-empty
- Quantity must be greater than 0
- Expiry date must be after production date and current block
- Genetic hash must be exactly 32 bytes
Verifies the authenticity of a registered seed batch.
- Caller: Authorized verifiers only
- Parameters:
seed-id: Unique seed identifiernotes: Verification notes and observations
- Returns:
(ok true)on success - Validations:
- Seed must exist and not be already verified
- Seed must not be expired
- Notes must be non-empty
Revokes verification status of a seed batch.
- Caller: Authorized verifiers only
- Parameters:
seed-id: Unique seed identifierreason: Reason for revocation
- Returns:
(ok true)on success - Validations:
- Seed must exist and be currently verified
- Reason must be non-empty
Transfers seed ownership to another party.
- Caller: Current seed owner only
- Parameters:
seed-id: Unique seed identifierrecipient: New owner's principal address
- Returns:
(ok true)on success
Updates the verification fee (future use).
- Caller: Contract owner only
- Parameters:
new-fee- New fee amount in microSTX - Returns:
(ok true)on success
Returns complete information about a seed batch.
- Returns:
(optional seed-record)or none
Returns the current owner of a seed batch.
- Returns:
(optional principal)or none
Checks if a seed is currently verified.
- Returns:
(ok bool)or error
Checks if an address is an authorized verifier.
- Returns:
(ok bool)
Checks if an address is a registered producer.
- Returns:
(ok bool)
Retrieves a specific verification history entry.
- Returns:
(optional verification-record)or none
Returns the current verification fee.
- Returns:
(ok uint)- Fee in microSTX
Returns the total number of seeds registered.
- Returns:
(ok uint)
Checks if a seed batch has expired.
- Returns:
(ok bool)- true if not expired, false if expired
{
producer: principal,
seed-type: (string-ascii 50),
batch-number: (string-ascii 50),
production-date: uint,
expiry-date: uint,
quantity: uint,
verified: bool,
verification-date: uint,
verifier: (optional principal),
genetic-hash: (buff 32),
origin: (string-ascii 100)
}{
verifier: principal,
timestamp: uint,
status: bool,
notes: (string-ascii 200)
}| Code | Constant | Description |
|---|---|---|
| u100 | err-owner-only | Function restricted to contract owner |
| u101 | err-not-found | Seed ID or record not found |
| u102 | err-already-exists | Record already exists |
| u103 | err-unauthorized | Caller lacks required authorization |
| u104 | err-invalid-data | Invalid input data provided |
| u105 | err-expired | Seed batch has expired |
| u106 | err-not-verified | Seed is not verified |
| u107 | err-already-verified | Seed is already verified |
| u108 | err-invalid-principal | Invalid principal address |
;; Register a producer
(contract-call? .seed-authenticity register-producer 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7)
;; Add a verifier
(contract-call? .seed-authenticity add-verifier 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE)(contract-call? .seed-authenticity register-seed
"Hybrid Maize GMO-453"
"BATCH-2025-001"
u12000 ;; production date (block height)
u50000 ;; expiry date (block height)
u10000 ;; quantity
0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
"Kenya, Rift Valley Region")(contract-call? .seed-authenticity verify-seed
u1
"Genetic analysis confirms authenticity. Germination rate: 98%. Quality excellent.")(contract-call? .seed-authenticity is-seed-verified u1)
;; Returns: (ok true)
(contract-call? .seed-authenticity get-seed-info u1)
;; Returns: complete seed record- Deploy the contract to Stacks blockchain
- Contract deployer is automatically set as owner, verifier, and producer
- Add additional verifiers using
add-verifier - Register producers using
register-producer - Producers can begin registering seeds
- All input data is validated before storage
- Role-based access control prevents unauthorized actions
- Verification history is immutable once recorded
- Genetic hashes provide cryptographic proof of seed identity
- Expiry dates prevent use of outdated seed batches
- Transfer functionality maintains accountability through ownership tracking
- Agricultural Supply Chain: Track seed authenticity from producer to farmer
- Quality Assurance: Verify seed genetics and quality standards
- Regulatory Compliance: Maintain immutable records for regulatory audits
- Fraud Prevention: Detect and prevent counterfeit seed distribution
- Insurance Claims: Provide verifiable proof of seed quality for crop insurance
- Research & Development: Track seed performance across regions and seasons