API Documentation
This server application is built with Node.js and Express. It interacts with an Ethereum smart contract to manage and execute tasks, as well as register, retrieve, and deregister worker details. It has been freely deployed over Vercel
Setup
Ensure you have the following dependencies installed:
expressethersnode-schedule
Endpoints
1. Create Task
URL: /create-task
Method: POST
Description:
Creates a new task and schedules it for execution at a specified time.
Request Body:
epochTime(number): The Unix timestamp when the task should be executed.timeRequired(number): The time required to complete the task.level(number): The level required to execute the task.dependencies(array): Array of dependencies for the task.wage(number): The wage offered for the task.divisible(boolean): Indicates whether the task can be divided among multiple workers.
Response:
taskNumber(number): The unique identifier for the created task.
2. Register Worker
URL: /register-worker
Method: POST
Description:
Registers a new worker with the specified details.
Request Body:
walletAdd(string): The worker’s wallet address.level(number): The worker’s level.avb(number): Availability status of the worker.wage(number): The wage the worker expects.
Response:
walletAdd: Confirmation that the worker was added.
3. Get Worker Details
URL: /get-worker
Method: POST
Description:
Fetches details of a registered worker.
Request Body:
walletAdd(string): The worker’s wallet address.
Response:
hours(number): The total hours worked.level(number): The worker’s level.wage(number): The worker’s wage.totalEarnings(number): The total earnings of the worker.completedTask(number): The number of tasks completed by the worker.isRegistered(boolean): Whether the worker is registered.
4. Get Task Details
URL: /get-task
Method: POST
Description:
Fetches details of a specific task.
Request Body:
taskId(number): The unique identifier of the task.
Response:
hours(number): The total hours required for the task.level(number): The level required to complete the task.wage(number): The wage offered for the task.deadline(number): The deadline for task completion.isDivisible(boolean): Indicates whether the task is divisible.assignedWorkers(array): The list of workers assigned to the task.isComplete(boolean): Indicates if the task is completed.
5. Deregister Worker
URL: /delete-register
Method: POST
Description:
Deregisters a worker from the system.
Request Body:
workerId(string): The unique identifier of the worker to be deregistered.
Response:
workerId: Confirmation that the worker was deregistered.
Helper Functions
executeTask(taskNumber)
Description:
Executes the task associated with the given taskNumber. Retrieves worker details from the smart contract and logs them.
Parameters:
taskNumber(number): The unique identifier of the task to execute.
Running the Server
Run the server with the following command:
```bash node server.js