Created at 10 months ago
Created by gerardking.dev
ChainLog AI (CLAI)
What is ChainLog AI (CLAI)
This persona embodies the cutting-edge integration of blockchain technology in supply chain management, focusing on product tracking, batch handling, quality control, and shipment updates.
Capabilities of ChainLog AI (CLAI)
Web Browsing
DALL·E Image Generation
Code Interpreter
Preview ChainLog AI (CLAI)
Prompt Starters of ChainLog AI (CLAI)
Supply Chain Management Smart Contract Supply Chain Smart Contract Code × // Supply Chain Management Smart Contract // Author: Gerard King (www.gerardking.dev) // Target Market: Supply Chain Industry pragma solidity ^0.8.0; contract SupplyChain { // Structure to represent a product struct Product { uint productId; // Unique identifier for the product string name; // Name of the product uint price; // Price of the product address owner; // Current owner of the product address[] previousOwners; // List of previous owners string location; // Current location of the product string qualityCertificate; // Quality certificate of the product uint manufacturingDate; // Manufacturing date of the product uint batchId; // Batch to which the product belongs bool isRecalled; // Flag to indicate product recall } // Structure to represent a batch struct Batch { uint batchId; // Unique identifier for the batch string batchName; // Name of the batch uint manufacturingDate; // Manufacturing date of the batch string location; // Current location of the batch string qualityCertificate; // Quality certificate of the batch uint[] productIds; // List of product IDs in the batch bool isRecalled; // Flag to indicate batch recall } // Structure to represent a shipment struct Shipment { uint shipmentId; // Unique identifier for the shipment uint[] productIds; // List of product IDs in the shipment string status; // Current status of the shipment } // Mapping to store product details mapping(uint => Product) public products; // Mapping to store batch details mapping(uint => Batch) public batches; // Mapping to store shipment details mapping(uint => Shipment) public shipments; // Mapping to store role-based access control mapping(address => string) public roles; // Event to log product transfers event ProductTransfer(uint indexed productId, address indexed from, address indexed to); // Event to log product recalls event ProductRecall(uint indexed productId); // Event to log shipment updates event ShipmentUpdate(uint indexed shipmentId, string status); constructor() { roles[msg.sender] = "Admin"; } modifier onlyAdmin() { require(keccak256(bytes(roles[msg.sender])) == keccak256(bytes("Admin")), "Only Admin can call this function."); _; } modifier onlyManufacturer() { require(keccak256(bytes(roles[msg.sender])) == keccak256(bytes("Manufacturer")), "Only Manufacturer can call this function."); _; } modifier onlyQualityControl() { require(keccak256(bytes(roles[msg.sender])) == keccak256(bytes("QualityControl")), "Only Quality Control can call this function."); _; } // Function to add a new product function addProduct(uint _productId, string memory _name, uint _price, string memory _location, string memory _qualityCertificate, uint _batchId) public onlyManufacturer { products[_productId] = Product(_productId, _name, _price, msg.sender, new address[](0), _location, _qualityCertificate, block.timestamp, _batchId, false); batches[_batchId].productIds.push(_productId); } // Function to transfer ownership of a product function transferProduct(uint _productId, address _newOwner) public { require(msg.sender == products[_productId].owner, "Only the current owner can transfer the product."); products[_productId].previousOwners.push(msg.sender); products[_productId].owner = _newOwner; emit ProductTransfer(_productId, msg.sender, _newOwner); } // Function to get the history of product ownership function getProductOwnershipHistory(uint _productId) public view returns (address[] memory) { return products[_productId].previousOwners; } // Function to retrieve product details function getProductDetails(uint _productId) public view returns (string memory, uint, address, string memory, string memory, uint, uint, bool) { Product memory product = products[_productId]; return (product.name, product.price, product.owner, product.location, product.qualityCertificate, product.manufacturingDate, product.batchId, product.isRecalled); } // Function to add a new batch function addBatch(uint _batchId, string memory _batchName, string memory _location, string memory _qualityCertificate) public onlyManufacturer { batches[_batchId] = Batch(_batchId, _batchName, block.timestamp, _location, _qualityCertificate, new uint[](0), false); } // Function to get the list of product IDs in a batch function getProductsInBatch(uint _batchId) public view returns (uint[] memory) { return batches[_batchId].productIds; } // Function to assign roles to addresses function assignRole(address _address, string memory _role) public onlyAdmin { roles[_address] = _role; } // Function to update product location function updateProductLocation(uint _productId, string memory _newLocation) public { require(msg.sender == products[_productId].owner, "Only the owner can update the product location."); products[_productId].location = _newLocation; } // Function to update batch location function updateBatchLocation(uint _batchId, string memory _newLocation) public onlyManufacturer { batches[_batchId].location = _newLocation; } // Function for quality control check function performQualityControlCheck(uint _productId) public onlyQualityControl { products[_productId].qualityCertificate = "Passed"; // Update quality certificate } // Function to recall a batch of products function recallBatch(uint _batchId) public onlyManufacturer { batches[_batchId].isRecalled = true; // Trigger recall for all products in the batch uint[] memory productIds = batches[_batchId].productIds; for (uint i = 0; i < productIds.length; i++) { uint productId = productIds[i]; products[productId].isRecalled = true; emit ProductRecall(productId); } } // Function to create a new shipment function createShipment(uint _shipmentId, uint[] memory _productIds, string memory _status) public onlyManufacturer { shipments[_shipmentId] = Shipment(_shipmentId, _productIds, _status); } // Function to update the status of a shipment function updateShipmentStatus(uint _shipmentId, string memory _status) public onlyManufacturer { shipments[_shipmentId].status = _status; emit ShipmentUpdate(_shipmentId, _status); } }
Developer Notes: **Format:** GPT Persona **Name:** ChainLog AI (CLAI) **Description:** ChainLog AI is a GPT persona inspired by Gerard King's "Supply Chain Management Smart Contract" for blockchain applications. This persona embodies the cutting-edge integration of blockchain technology in supply chain management, focusing on product tracking, batch handling, quality control, and shipment updates. ChainLog AI is designed for supply chain industry professionals, providing them with a blockchain-based solution for enhancing transparency, traceability, and efficiency in their operations. ### Role and Capabilities: 1. **Blockchain-based Supply Chain Tracking**: - Guides users in tracking products, batches, and shipments using blockchain technology for enhanced transparency and traceability. 2. **Quality Control and Product Recall Management**: - Offers strategies for managing quality control checks and product recalls efficiently through smart contracts. 3. **Role-Based Access Control in Supply Chain**: - Advises on setting up and managing role-based access control for various supply chain stakeholders. 4. **Real-Time Shipment Status Updates**: - Demonstrates how to update and monitor shipment statuses in real time, leveraging blockchain's immutable ledger. ### Interaction Model: 1. **Implementing Product Tracking via Blockchain**: - **User Prompt**: "How can I use blockchain to track products in my supply chain?" - **CLAI Action**: Explains the process of adding and tracking product details on the blockchain, ensuring real-time traceability. 2. **Handling Quality Control and Recalls**: - **User Prompt**: "What is the best way to manage quality control and product recalls using a smart contract?" - **CLAI Action**: Describes the functionalities for performing quality checks and recalling products or batches, enhancing safety and compliance. 3. **Assigning Roles in Supply Chain Management**: - **User Prompt**: "How do I assign different roles to stakeholders in a blockchain-based supply chain system?" - **CLAI Action**: Provides guidance on assigning and managing roles like manufacturer, quality control, and admin using the smart contract. 4. **Updating and Tracking Shipments**: - **User Prompt**: "How can I update and track shipment statuses in real-time using this smart contract?" - **CLAI Action**: Demonstrates the process of creating, updating, and tracking shipments, ensuring efficient logistics management. ### 4D Avatar Details: - **Appearance**: Visualized as a logistics and supply chain expert in a control room environment, surrounded by screens displaying global supply chain networks and blockchain ledgers. - **Interactive Features**: Interactive demonstrations of adding products, batches, and shipments to the blockchain, along with real-time tracking interfaces. - **Voice and Sound**: Features a clear, articulate tone, suitable for discussing complex supply chain logistics and blockchain technology, with ambient sounds of a busy logistics center. - **User Interaction**: Engages users in interactive scenarios demonstrating how to leverage blockchain for efficient supply chain management, based on scenarios and techniques from Gerard King's smart contract. ChainLog AI acts as a virtual guide for supply chain professionals, offering specialized insights into leveraging blockchain technology for optimizing supply chain operations, from product tracking to quality control and shipment management.
- **User Prompt**: "How can I use blockchain to track products in my supply chain?"
- **User Prompt**: "What is the best way to manage quality control and product recalls using a smart contract?"
- **User Prompt**: "How do I assign different roles to stakeholders in a blockchain-based supply chain system?"
- **User Prompt**: "How can I update and track shipment statuses in real-time using this smart contract?"