Skip to content

The Seed Authenticity Verification smart contract is a comprehensive blockchain-based solution designed to combat agricultural fraud by creating a transparent, immutable system for tracking and verifying seed authenticity throughout the agricultural supply chain.

Notifications You must be signed in to change notification settings

chike-smith/Seed-Authenticity-Verification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Seed Authenticity Verification Smart Contract

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.

Features

Core Functionality

  • 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

Security & Access Control

  • 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

Contract Roles

Contract Owner

  • Deployer of the contract
  • Can add/remove authorized verifiers
  • Can register new producers
  • Can update verification fees
  • Automatically registered as both verifier and producer

Authorized Verifiers

  • Can verify seed authenticity
  • Can revoke existing verifications
  • Access to verification functions only

Registered Producers

  • Can register new seed batches
  • Can transfer seed ownership
  • Must be registered by contract owner

Public Functions

Authorization Management

add-verifier (verifier principal)

Adds a new authorized verifier to the system.

  • Caller: Contract owner only
  • Parameters: verifier - Principal address to authorize
  • Returns: (ok true) on success

remove-verifier (verifier principal)

Removes an authorized verifier from the system.

  • Caller: Contract owner only
  • Parameters: verifier - Principal address to deauthorize
  • Returns: (ok true) on success

register-producer (producer principal)

Registers a new seed producer.

  • Caller: Contract owner only
  • Parameters: producer - Principal address to register
  • Returns: (ok true) on success

Seed Management

register-seed

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 identifier
    • production-date (uint): Block height of production
    • expiry-date (uint): Block height when seed expires
    • quantity (uint): Number of seeds in batch
    • genetic-hash (buff 32): 32-byte genetic fingerprint
    • origin (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

verify-seed (seed-id uint) (notes string-ascii 200)

Verifies the authenticity of a registered seed batch.

  • Caller: Authorized verifiers only
  • Parameters:
    • seed-id: Unique seed identifier
    • notes: 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

revoke-verification (seed-id uint) (reason string-ascii 200)

Revokes verification status of a seed batch.

  • Caller: Authorized verifiers only
  • Parameters:
    • seed-id: Unique seed identifier
    • reason: Reason for revocation
  • Returns: (ok true) on success
  • Validations:
    • Seed must exist and be currently verified
    • Reason must be non-empty

transfer-seed (seed-id uint) (recipient principal)

Transfers seed ownership to another party.

  • Caller: Current seed owner only
  • Parameters:
    • seed-id: Unique seed identifier
    • recipient: New owner's principal address
  • Returns: (ok true) on success

update-verification-fee (new-fee uint)

Updates the verification fee (future use).

  • Caller: Contract owner only
  • Parameters: new-fee - New fee amount in microSTX
  • Returns: (ok true) on success

Read-Only Functions

get-seed-info (seed-id uint)

Returns complete information about a seed batch.

  • Returns: (optional seed-record) or none

get-seed-owner (seed-id uint)

Returns the current owner of a seed batch.

  • Returns: (optional principal) or none

is-seed-verified (seed-id uint)

Checks if a seed is currently verified.

  • Returns: (ok bool) or error

is-authorized-verifier (verifier principal)

Checks if an address is an authorized verifier.

  • Returns: (ok bool)

is-registered-producer (producer principal)

Checks if an address is a registered producer.

  • Returns: (ok bool)

get-verification-history (seed-id uint) (index uint)

Retrieves a specific verification history entry.

  • Returns: (optional verification-record) or none

get-verification-fee

Returns the current verification fee.

  • Returns: (ok uint) - Fee in microSTX

get-seed-counter

Returns the total number of seeds registered.

  • Returns: (ok uint)

check-seed-expiry (seed-id uint)

Checks if a seed batch has expired.

  • Returns: (ok bool) - true if not expired, false if expired

Data Structures

Seed Record

{
  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)
}

Verification History

{
  verifier: principal,
  timestamp: uint,
  status: bool,
  notes: (string-ascii 200)
}

Error Codes

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

Usage Example

1. Setup (Contract Owner)

;; Register a producer
(contract-call? .seed-authenticity register-producer 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7)

;; Add a verifier
(contract-call? .seed-authenticity add-verifier 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE)

2. Register Seeds (Producer)

(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")

3. Verify Seeds (Verifier)

(contract-call? .seed-authenticity verify-seed
  u1
  "Genetic analysis confirms authenticity. Germination rate: 98%. Quality excellent.")

4. Check Verification Status

(contract-call? .seed-authenticity is-seed-verified u1)
;; Returns: (ok true)

(contract-call? .seed-authenticity get-seed-info u1)
;; Returns: complete seed record

Deployment

  1. Deploy the contract to Stacks blockchain
  2. Contract deployer is automatically set as owner, verifier, and producer
  3. Add additional verifiers using add-verifier
  4. Register producers using register-producer
  5. Producers can begin registering seeds

Security Considerations

  • 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

Use Cases

  • 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

About

The Seed Authenticity Verification smart contract is a comprehensive blockchain-based solution designed to combat agricultural fraud by creating a transparent, immutable system for tracking and verifying seed authenticity throughout the agricultural supply chain.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published