Skip to content

Instantly share code, notes, and snippets.

@shobhitic
Last active October 31, 2022 10:32
Show Gist options
  • Save shobhitic/080f4624eba28024ef3657b879ab6796 to your computer and use it in GitHub Desktop.
Save shobhitic/080f4624eba28024ef3657b879ab6796 to your computer and use it in GitHub Desktop.
TodoList Backend in Solidity - https://www.youtube.com/watch?v=20ktZBancco
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract TodoList {
struct TodoItem {
string task;
bool isCompleted;
}
mapping (uint256 => TodoItem) public list;
uint256 public count = 0;
address public owner;
event TaskCompleted(uint256 indexed id);
constructor () {
owner = msg.sender;
}
function addTask(string calldata task) onlyOwner public {
TodoItem memory item = TodoItem({ task: task, isCompleted: false });
list[count] = item;
count++;
}
function completeTask(uint256 id) onlyOwner public {
if (!list[id].isCompleted) {
list[id].isCompleted = true;
emit TaskCompleted(id);
}
}
modifier onlyOwner() {
require(owner == msg.sender, "Only owner can call this");
_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment