Skip to content

A Solidity smart contract for decentralized pet registration and management on the Ethereum blockchain.

License

Notifications You must be signed in to change notification settings

aggsakellariou/Pet-Management

Repository files navigation

Pet Management Smart Contract

A blockchain-based pet registration and management system built with Solidity.

Overview

This project implements a decentralized pet management system using Ethereum smart contracts. Pet owners can register their pets with unique chip IDs, update pet information, and manage pet records on the blockchain.

Features

  • Pet Registration: Register pets with unique chip IDs
  • Pet Information Management: Update pet names and ages
  • Pet Removal: Remove pets from active registry with reasons
  • Ownership Verification: Only pet owners can modify their pet's information
  • Data Integrity: Built-in validation for pet data

Smart Contract Details

Contract: PetManagement

Key Functions

  • registerPet(uint32 petId, string petName, string petSpecies, uint8 petAge): Register a new pet
  • updatePetName(uint32 petId, string petNewName): Update pet's name
  • incrementPetAge(uint32 petId): Increment pet's age by 1
  • removePet(uint32 petId, string petReason): Remove pet from active registry
  • getPet(uint32 petId): Retrieve pet information

Data Structure

struct Pet {
    uint32 chipId;      // Unique chip identifier
    string name;        // Pet name (max 32 characters)
    string species;     // Pet species (max 32 characters)
    uint8 age;          // Pet age (max 50)
    bool isActive;      // Active status
    string removalReason; // Reason for removal (if inactive)
    address owner;      // Owner's Ethereum address
}

Constraints

  • Maximum pet age: 50 years
  • Maximum name length: 32 characters
  • Maximum species length: 32 characters
  • Each chip ID can only be used once
  • Only active pet owners can modify their pet's information

Getting Started

Prerequisites

Deployment

  1. Using Remix IDE (Recommended for beginners):

    • Open Remix IDE
    • Create a new file and paste the contract code from Pet_Management.sol
    • Compile the contract using Solidity compiler 0.8.x
    • Deploy to your preferred network (Ganache, Sepolia testnet, etc.)
  2. Using Hardhat (Advanced):

    npm install --save-dev hardhat
    npx hardhat init
    # Copy Pet_Management.sol to contracts/
    npx hardhat compile
    npx hardhat run scripts/deploy.js --network <network-name>
  3. Using Truffle (Advanced):

    npm install -g truffle
    truffle init
    # Copy Pet_Management.sol to contracts/
    truffle compile
    truffle migrate --network <network-name>

Security Considerations

  • Access Control: Only pet owners can modify their pet's information
  • Data Validation: All inputs are validated for length and format
  • Immutable Records: Pet registration creates permanent blockchain records
  • Gas Optimization: Functions are optimized for minimal gas consumption

Acknowledgments

  • Built with Solidity ^0.8.2
  • Follows Ethereum best practices
  • Implements secure smart contract patterns

About

A Solidity smart contract for decentralized pet registration and management on the Ethereum blockchain.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published