A basic todo list smart contract built with ink! v5.1.1, demonstrating simple data storage patterns using Vec-based storage for task management.
This contract implements a simple todo list system with:
- Task Management: Add, complete, and remove tasks
- Vec Storage: Simple vector-based storage pattern
- Basic Operations: Core CRUD functionality
- Simple Design: Easy to understand and extend
lib.rs- Main contract implementation- Vec Storage: Simple vector-based task storage
- Task Struct: Basic task data structure
pub struct Task {
pub id: u32,
pub description: String,
pub completed: bool,
}
pub struct Todo {
tasks: Vec<Task>, // Vector of tasks
next_id: u32, // Next available ID
}- Add Task: Create new todo items
- Complete Task: Mark tasks as done
- Remove Task: Delete tasks from the list
- Get Tasks: Retrieve all tasks
- Get Task: Retrieve specific task by ID
- Vec-based: Uses Rust's Vec for storage
- Sequential IDs: Auto-incrementing task IDs
- Simple Queries: Basic task retrieval
# Development build
cargo contract build
# Production build
cargo contract build --release# Deploy to local node
cargo contract instantiate --constructor new --suri //Alice --skip-confirm// Add a new task
add_task(description: String) -> u32
// Mark task as complete
complete_task(id: u32) -> bool
// Remove a task
remove_task(id: u32) -> bool
// Get all tasks
get_tasks() -> Vec<Task>
// Get specific task
get_task(id: u32) -> Option<Task>cargo testcargo test --features e2e-testsThe contract includes tests covering:
- Task creation
- Task completion
- Task removal
- Task retrieval
- Edge cases
- Error conditions
// Create a new todo contract
let mut todo = Todo::new();
// Add tasks
let task1_id = todo.add_task("Buy groceries".to_string());
let task2_id = todo.add_task("Walk the dog".to_string());
// Complete a task
todo.complete_task(task1_id);
// Get all tasks
let all_tasks = todo.get_tasks();
// Remove a task
todo.remove_task(task2_id);[dependencies]
ink = { version = "5.1.1", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.11", default-features = false, features = ["derive"] }- Daily Tasks: Personal todo lists
- Project Management: Simple project tracking
- Habit Tracking: Daily habit monitoring
- Goal Setting: Personal goal management
- Learning ink!: Introduction to smart contracts
- Storage Patterns: Understanding Vec storage
- Basic CRUD: Database-like operations
- Contract Development: First contract example
- Task Sharing: Shared todo lists
- Team Coordination: Basic team task management
- Event Planning: Simple event task lists
- Workflow Management: Basic process tracking
- Basic Access: No access control (anyone can modify)
- Simple Validation: Basic input checking
- No Complex Logic: Straightforward operations
- No Access Control: Anyone can modify tasks
- No Data Validation: Limited input validation
- Simple Storage: Not optimized for large datasets
- Vec Storage: Linear search for tasks
- Memory Usage: Grows with number of tasks
- Query Time: O(n) for task lookup
- Simple Operations: Fast for small datasets
- Small Datasets: Good for < 100 tasks
- Large Datasets: May become slow
- Memory Growth: Linear with task count
| Feature | Simple Todo | Todo Map |
|---|---|---|
| Storage | Vec | Mapping |
| Lookup | O(n) | O(1) |
| Memory | Linear | Constant |
| Scalability | Limited | Better |
| Complexity | Simple | More complex |
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is provided as-is for educational purposes. Check the main repository for licensing information.
For issues and questions:
- Create an issue in the repository
- Check the main README for troubleshooting
- Review the ink! documentation
🦀 Built with Rust + ink! v5.1.1
This simple todo contract demonstrates basic smart contract development patterns and serves as an excellent starting point for learning ink! development.
