Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ASSIGNMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Todo Contract Assignment

## Overview
This is the Todo contract assignment (as-w3-d1). The Todo contract provides functionality for task management.

## Setup
1. Install dependencies: `npm install`
2. Configure hardhat: See `hardhat.config.ts`
3. Run tests: `npm test`

## Contract Details
- **Location**: `Assignment/solidity-assignment7/contracts/todo/`
- **Language**: Solidity

## Testing
```bash
npm test
```

## Deployment
```bash
npx hardhat run scripts/deploy.ts
```
70 changes: 70 additions & 0 deletions Assignment/solidity-assignment7/contracts/todo/contracts/Todo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

contract Todo {
uint public todoCounter;

enum TaskState {
Pending,
Completed,
Cancelled,
Defaulted
}

struct Task {
uint id;
address admin;
string text;
TaskState status;
uint deadline;
}

mapping(uint => Task) tasks;
event TaskCreated(string text, uint deadline);

function createTask(
string memory text,
uint deadline
) external returns (uint) {
require(bytes(text).length > 0, 'Text cannot be empty');
require(deadline > (block.timestamp + 600), 'Invalid deadline');

todoCounter++;

tasks[todoCounter] = Task(
todoCounter,
msg.sender,
text,
TaskState.Pending,
deadline
);

emit TaskCreated(text, deadline);
return todoCounter;
}

function getTask(uint id) external view returns (Task memory) {
return tasks[id];
}

function updateTask(
uint id,
string memory text,
uint deadline
) external returns (uint) {
require(bytes(text).length > 0, 'Text cannot be empty');
require(
deadline > (block.timestamp + 600),
'Deadline cannot be less than 10 minutes'
);
require(tasks[id].admin == msg.sender, 'Only admin can update task');
tasks[id] = Task(id, msg.sender, text, TaskState.Pending, deadline);
return id;
}

function doneTask(uint id) external returns (uint) {
require(tasks[id].admin == msg.sender, 'Only admin can complete task');
tasks[id].status = TaskState.Completed;
return id;
}
}
45 changes: 45 additions & 0 deletions Assignment/solidity-assignment7/contracts/todo/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import dotenv from "dotenv";
dotenv.config({ path: "../../.env" });
import hardhatToolboxViemPlugin from "@nomicfoundation/hardhat-toolbox-viem";
import { configVariable, defineConfig } from "hardhat/config";

export default defineConfig({
plugins: [hardhatToolboxViemPlugin],
solidity: {
profiles: {
default: {
version: "0.8.28",
},
production: {
version: "0.8.28",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
},
},
networks: {
hardhatMainnet: {
type: "edr-simulated",
chainType: "l1",
},
hardhatOp: {
type: "edr-simulated",
chainType: "op",
},
sepolia: {
type: "http",
chainType: "l1",
url: configVariable("SEPOLIA_RPC_URL"),
accounts: [configVariable("SEPOLIA_PRIVATE_KEY")],
},
},
verify: {
etherscan: {
apiKey: configVariable("ETHERSCAN_API_KEY"),
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

export default buildModule("TodoModule", (m) => {
const todo = m.contract("Todo");

return { todo };
});
17 changes: 17 additions & 0 deletions Assignment/solidity-assignment7/contracts/todo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "New Folder",
"version": "1.0.0",
"type": "module",
"devDependencies": {
"@nomicfoundation/hardhat-ignition": "^3.0.7",
"@nomicfoundation/hardhat-toolbox-viem": "^5.0.2",
"@types/node": "^22.19.8",
"forge-std": "github:foundry-rs/forge-std#v1.9.4",
"hardhat": "^3.1.6",
"typescript": "~5.8.0",
"viem": "^2.45.1"
},
"dependencies": {
"dotenv": "^17.2.4"
}
}
13 changes: 13 additions & 0 deletions Assignment/solidity-assignment7/contracts/todo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Based on https://github.com/tsconfig/bases/blob/501da2bcd640cf95c95805783e1012b992338f28/bases/node22.json */
{
"compilerOptions": {
"lib": ["es2023"],
"module": "node16",
"target": "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node16",
"outDir": "dist"
}
}
9 changes: 9 additions & 0 deletions template/.github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Summary
What does this PR implement?

## Testing
- [ ] Unit tests added
- [ ] Tests passing locally

## Notes
Any assumptions or trade-offs?
24 changes: 24 additions & 0 deletions template/.github/workflows/.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
formatting:
name: Code Formatting (Prettier)
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Run Prettier check
run: npx prettier --check .
5 changes: 5 additions & 0 deletions template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
.vscode/

package-lock.json
node_modules
4 changes: 4 additions & 0 deletions template/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
build
.env*
7 changes: 7 additions & 0 deletions template/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80,
"tabWidth": 2
}
35 changes: 35 additions & 0 deletions template/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# How to Contribute

1. Getting Started
- Fork the repository
- Sync with upstream
- Create a feature branch

2. Branch Naming Convention
Example:
`submission/assignment-01/<github-username>`

3. Commit Message Guidelines

Example (Conventional Commits–lite):
```
feat: implement token transfer logic
fix: handle zero-address edge case
test: add coverage for revert conditions
```

4. Pull Request Checklist
- [x] Code compiles
- [x] Tests pass
- [x] README included
- [x] No changes outside /submissions

5. PR Review Process
- [x] Automated checks
- [x] Manual review by mentors
- [x] Required fixes before merge

6. Common Mistakes to Avoid
- Editing assignment specs
- Submitting compiled artifacts
- Force-pushing after review
26 changes: 26 additions & 0 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Cohort 8
Blockchain Development Bootcamp — Cohort 8

This repository contains official technical materials, specifications, assignments, and collaboration artifacts for the 8th edition of our blockchain program. Dev participants are expected to actively use this repository throughout the program for learning, development, version control, and peer collaboration.

#### Repository Structure
The repository will evolve over time, but a typical structure looks like:
```cohort-8/
├── README.md # Repository overview and instructions
├── assignments/ # Coding exercises and assessments
├── projects/
│ ├── templates/ # Starter project templates
│ └── submissions/ # Participant or team submissions
└── resources/ # Technical references & reading material
```

#### Setup
Clone the repository:
```
git clone https://github.com/BlockheaderWeb3-Community/cohort-8.git
cd cohort-8
```

#### Code Formatting
This repository uses Prettier for formatting. Install the Prettier extension in your editor and enable Format on Save.