A blockchain-based pet registration and management system built with Solidity.
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.
- 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
registerPet(uint32 petId, string petName, string petSpecies, uint8 petAge)
: Register a new petupdatePetName(uint32 petId, string petNewName)
: Update pet's nameincrementPetAge(uint32 petId)
: Increment pet's age by 1removePet(uint32 petId, string petReason)
: Remove pet from active registrygetPet(uint32 petId)
: Retrieve pet information
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
}
- 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
- Node.js (v14 or higher)
- npm or yarn
- MetaMask or another Ethereum wallet
- Remix IDE (for deployment and testing)
-
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.)
-
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>
-
Using Truffle (Advanced):
npm install -g truffle truffle init # Copy Pet_Management.sol to contracts/ truffle compile truffle migrate --network <network-name>
- 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
- Built with Solidity ^0.8.2
- Follows Ethereum best practices
- Implements secure smart contract patterns