PetPet turns real pet care into privacy-safe, verifiable events in an on-chain explorer and dashoard

PetPet is a revolutionary pet-first blockchain explorer where each pet is represented by a uniquely named smart contract deployed on-chain, creating a verifiable, tamper-proof "digital twin" that tracks real-world activities while preserving privacy through Trusted Execution Environments (TEE). The project solves a fundamental trust problem in pet care: there's no unified, trustworthy way to verify pet activities and care records. Daycare updates are fragmented and easily fabricated, vets and boarders lack standardized tamper-evident records for feeding, medications, and checkups, and most critically, existing pet tracking solutions expose sensitive location data publicly, creating serious privacy and security risks. PetPet addresses this through a multi-layered approach combining IoT hardware, computer vision, blockchain, and privacy-preserving computation. An ESP32 microcontroller with GPS module attached to the pet's collar captures real-time location coordinates, speed, and movement patterns, while webcams or smartphone cameras detect pet activity states like running, playing, eating, drinking, and sleeping using object detection models. All sensitive data—raw GPS coordinates and video feeds—is processed entirely within Phala Network's Trusted Execution Environment, a secure enclave where computer vision inference runs without any raw video or precise location data ever leaving the protected environment. The TEE performs privacy-preserving computations, calculating distance traveled, average speed, activity duration, and behavioral patterns, then generates cryptographic attestations proving data was processed correctly without exposing sensitive information. Only aggregated, TEE-attested metrics are published on-chain, such as "traveled 2.5km today" instead of exact coordinates, ensuring verifiability without invasiveness. Each pet gets a unique smart contract with a human-readable name like "Buddy_The_Dog" that's searchable directly in the Blockscout explorer, eliminating the need for ENS while providing the same benefits. The project features an immersive dashboard where users see their pet's 3D avatar that mirrors real-time behavior while activities are recorded on-chain simultaneously—when the physical pet runs, eats, or plays, the 3D avatar mirrors these actions instantly, creating a seamless digital twin experience. For pet owners, this provides trustless verification of pet care—if a dog walker claims they walked your dog for an hour, the on-chain record with TEE attestation cryptographically proves it. Vets and boarders gain access to complete, tamper-evident care histories to track recovery progress through objective measurements and build trust with clients through verifiable, immutable records. Unlike traditional GPS trackers that expose location data, PetPet processes everything in a TEE where raw coordinates never appear on-chain or in public APIs—only the owner and authorized parties can access detailed data while third parties see only aggregated, privacy-safe metrics. The project also serves rescue and community needs by providing public, searchable pet profiles that help reunite lost pets with owners while ensuring immutable care records prevent abuse and ensure accountability in pet care services.
PetPet is built as a Next.js full-stack application with smart contracts deployed on a custom blockchain (Chain ID 2403), integrated with Phala Network TEE for privacy-preserving computation and Blockscout for blockchain exploration. The frontend uses Next.js with the Pages Router for server-side rendering and API routes, React for component-based UI with hooks, Tailwind CSS for styling, Spline 3D Viewer for interactive 3D pet avatars that mirror real-time pet behavior, shadcn/ui for reusable components, Canvas API for real-time video processing, Geolocation API for browser-based GPS tracking, and WebSocket connections for live synchronization between physical pet activities and on-chain events. The backend consists of Solidity smart contracts, Hardhat for compilation and deployment, TypeScript for type-safe contract interactions, Phala Network TEE for secure data processing, and Anvil (Foundry) for local Ethereum node development. The blockchain infrastructure runs on a custom chain with a TEE-hosted RPC endpoint on Phala Network, a Blockscout Autoscout explorer launched via deploy.blockscout.com, and Blockscout API for contract verification and event indexing. The IoT layer includes ESP32 microcontrollers with GPS modules for collar-based tracking and computer vision models for activity classification. The core innovation treats each pet as a first-class blockchain citizen—when an owner creates a pet profile, the frontend calls an API route that compiles and deploys a new pet contract with a unique name to the Phala Network chain, and a PetRegistry smart contract maintains a central directory preventing duplicate names. The most notable innovation is the real-time 3D pet mirroring system: the dashboard displays a 3D avatar of the pet using Spline that mirrors real-world behavior in real-time while simultaneously recording on-chain—when the physical pet runs, the 3D avatar runs; when eating, it shows eating animations, creating an immersive digital twin experience where users watch their pet's virtual representation sync perfectly with reality while blockchain events verify every action cryptographically through WebSocket connections that trigger both Spline 3D animations and on-chain transaction submissions in parallel. The ESP32 board with GPS module runs lightweight firmware that reads coordinates every few seconds, calculates speed and cumulative distance, then sends raw sensor data via HTTP POST to Next.js API endpoints which act as a gateway to the TEE—this is a particularly hacky but elegant solution that avoids building separate IoT infrastructure by leveraging Next.js API routes as the data ingestion layer, simplifying deployment and using the same authentication system for web and IoT clients. For camera computer vision, webcams or smartphone cameras capture live video feeds that are sent to the TEE via API endpoints where object detection models identify pets and classify activity states, with duration tracking maintained by a TEE state machine—we initially tried running TensorFlow.js models client-side, but model size and inference speed were prohibitive on mobile devices, so offloading to TEE provides better performance and privacy since video goes directly to the secure enclave without hitting public servers. The Phala Network TEE integration is where the privacy magic happens: all sensitive data processing occurs inside the Trusted Execution Environment which runs confidential smart contracts (pink contracts) that receive raw GPS coordinates and video frames, perform computer vision inference entirely within the secure enclave, calculate privacy-preserving aggregates, generate cryptographic attestations, and submit only aggregated events to the pet's on-chain contract. Running full computer vision models inside a TEE required significant optimization—we had to quantize models, use TensorFlow Lite, and implement frame batching to fit within TEE memory constraints, but the benefit is absolute privacy where no cloud provider, developer, or third party ever sees raw location or video data. We launched a custom Blockscout instance using the Autoscout Self-Service Launchpad deployed via deploy.blockscout.com for Chain ID 2403, connected to the Phala Network TEE-hosted RPC endpoint, with contract verification configured to support pet contract search by name—each deployed pet contract is verified, making it searchable as "Buddy_The_Dog" instead of cryptic addresses. Phala Network TEE eliminated the trusted third party problem (even we as developers can't access raw data), enabled complex computation with privacy guarantees that zero-knowledge proofs cannot provide, and generated cryptographic attestations that build trust without exposing sensitive information. Blockscout Autoscout saved weeks of development time with its self-service deployment being remarkably smooth, and its contract verification system enabled human-readable pet names without ENS complexity while providing a public explorer for viewing pet contract events and transaction history. The ESP32 costs only $5-10, has low power consumption perfect for pet collars, built-in WiFi for data transmission, GPIO pins for GPS module integration, and the Arduino ecosystem makes firmware development accessible. Other notable hacks include using Next.js API routes as an IoT gateway, implementing TEE frame batching to process video frames in 5-second windows dramatically reducing latency and cost, leveraging Blockscout's verified contract search as "free ENS" without deploying ENS resolvers, creating a privacy-public hybrid where pet contracts store both public events and encrypted references to detailed TEE-processed data allowing owners to decrypt full GPS tracks while the public only sees aggregated metrics like "2.5km traveled today," and running a local Phala Network phat contract development environment during development to test TEE integration without deploying to mainnet which saved significant debugging time. We also made a particularly hacky architectural decision to deploy full contracts instead of using OpenZeppelin's Clone pattern (EIP-1167) for gas-efficient deployments because Blockscout's contract verification doesn't work well with minimal proxies—full contracts ensure each pet is verifiable and searchable by name in the explorer, prioritizing explorer UX over gas optimization. Major challenges we overcame included discovering that ZK circuits can't handle computer vision inference and pivoting to TEE, abandoning ENS in favor of Blockscout's contract verification for simpler deployment, heavily optimizing computer vision models to fit in TEE memory constraints, and implementing WebSocket fallback for low-latency activity updates when REST APIs were too slow.

