This project is a decentralized application (DApp) that allows users to manage a to-do list using a smart contract on the Ethereum blockchain. The project includes a Solidity smart contract and a frontend to interact with it.
To get started with this project, follow these instructions.
- Node.js (v14 or later)
- npm (v6 or later)
- Truffle (v5 or later)
- Ganache (for local development)
-
Clone the repository:
git clone https://github.com/yourusername/todo-dapp.git cd todo-dapp
-
Install dependencies:
npm install
-
Install foundry globally if you haven't already:
curl -L https://foundry.paradigm.xyz | bash
The smart contract is written in Solidity and provides the following functionalities:
- createTodo: Create a new to-do item.
- updateTodo: Update the title and description of an existing to-do item.
- markTodo: Mark a to-do item as completed or not completed.
- getTodo: Retrieve a specific to-do item.
- deleteTodo: Delete a to-do item.
- getAllTodo: Retrieve all to-do items.
pragma solidity 0.8.22;
contract Todo {
struct TodoList {
string title;
string description;
bool isCompleted;
}
TodoList[] public todo;
function createTodo(
string calldata _title,
string calldata _description
) external {
todo.push(TodoList(_title, _description, false));
}
function updateTodo(
uint _index,
string calldata _title,
string calldata _description
) external {
todo[_index].title = _title;
todo[_index].description = _description;
}
function markTodo(uint _index) external {
todo[_index].isCompleted = !todo[_index].isCompleted;
}
function getTodo(
uint _index
) external view returns (string memory, string memory, bool) {
TodoList memory todos = todo[_index];
return (todos.title, todos.description, todos.isCompleted);
}
function deleteTodo(uint _index) external {
delete todo[_index];
}
function getAllTodo() external view returns (TodoList[] memory) {
return todo;
}
}
The frontend is built with React and allows users to interact with the smart contract.
- Create a new to-do item
- Update an existing to-do item
- Mark a to-do item as completed or not completed
- Delete a to-do item
- View all to-do items
To start the frontend application, run:
npm start
This will launch the app in development mode and open http://localhost:3000 in your default browser.
-
Compile the smart contract:
forge b
-
Deploy the smart contract to a local blockchain:
forge t
- Ensure your Ethereum wallet (e.g., MetaMask) is connected to the same network where the smart contract is deployed.
- Open the frontend application.
- Use the interface to create, update, mark, delete, and view to-do items.
Contributions are welcome! Please submit a pull request or open an issue to discuss changes.
This project is licensed under the MIT License. See the LICENSE file for details.