Using Enums in Blockchain Smart Contracts
📖 Scenario: You are building a simple blockchain smart contract to manage the status of a package delivery. The package can be in one of several states: Pending, Shipped, Delivered, or Returned.Using an enum helps keep track of these states clearly and safely.
🎯 Goal: Create a Solidity smart contract that uses an enum to represent package delivery status. You will set the initial status, update it, and then display the current status.
📋 What You'll Learn
Create an
enum called Status with values Pending, Shipped, Delivered, and Returned.Create a state variable called
currentStatus of type Status.Set the initial
currentStatus to Pending.Write a function to update
currentStatus to Shipped.Write a function to get the current status as a string.
Print the current status after updating it.
💡 Why This Matters
🌍 Real World
Enums help track fixed states like package delivery status, voting phases, or contract stages in blockchain smart contracts.
💼 Career
Understanding enums is essential for blockchain developers to write clear, safe, and maintainable smart contracts.
Progress0 / 4 steps