This repository contains the smart contract code for payrollah registry (in /contracts
) as well as the node package for using this library (in /src
).
npm i @payrollah/payrollah-registry
This package contains the ABI for the payrollah smart contracts. To use the package, you will need to provide your own Web3 provider and signer/wallet.
Company will store the address, name and domain information of a given company registered with payrollah. You should be connecting to a global instance of Company contract at 0x27a7d618C8d67F8C57eb3eF4815f4C869242B0bE
.
Connecting to existing Company contract on Ethereum
import {Company__factory} from "@payrollah/payrollah-registry";
const connectedRegistry = Company__factory.connect(address, wallet);
List of available functions on Company
The contract supports all ERC721 methods with a few added functionality listed below:
- constructor(string
name
, stringsymbol
) - Will be used to initialize the contract - companies(int
companyId
) - Given companyId return company information - createCompany(string
name
, stringdomain
) - Register new company with Company contract - getCompanyAddress(int
companyId
) - Returns company wallet address - getCompanyIdByAddress(address
companyAddress
) - Get all companyId from Address - isActiveCompany(int
companyId
) - Check if company isActive - isExistingCompany(int
companyId
) - Check if company is existing - isValidCompany(int
companyId
) - Check if company is valid - isValidCompanyAddress(address
companyAddress
) - Check if company address given is valid - disableCompany(uint256
companyId
) - Disable company from smart contract (a way to leave the platform)
Worker contract currently just stores the workers address and whether he is active on the platform. We decided to use NFT token here for future scalability in the event that we may want to expand through storing more verification information. You can connect to the Worker contract we have deployed at 0xfC16D162C6a9Ff85346cB42176428c26278F09D1
.
Connecting to existing Worker contract on Ethereum
import {Worker__factory} from "@payrollah/payrollah-registry";
const connectedRegistry = Worker__factory.connect(address, wallet);
List of available functions on Worker contract
The contract supports all ERC721 methods with a few added functionality listed below:
- constructor(string
name
, stringsymbol
) - Will be used to initialize the contract - workers(int
workerId
) - Return worker information by id - createWorker() - Register new worker with Worker contract
- getWorkerAddress(int
workerId
) - Get address from workerId - getWorkerIdByAddress(address
workerAddress
) - Returns workerId by address - isActiveWorker(int
workerId
) - Check if the worker account is active - isExistingWorker(int
workerId
) - Check if the worker exist on the contract - isValidWorker(int
workerId
) - Check if worker is valid - isValidWorkerAddress(address
workerAddress
) - Check if given address is a valid worker - disableWorker(int
workerId
) - Disable worker from smart contract (a way to leave the platform)
Task stores all the past task created, who completed it, who endorsed it and its current status. We have decided to make all tasks public for now as we want to allow future company to be able to see the previous work done by worker.
You can connect to the Task contract we have deployed at 0x2fBd0b674B86BBb7Fb7CC76cD815be95eeCcE6c9
.
Connecting to existing Task contract on Ethereum
import {Task__factory} from "@payrollah/payrollah-registry";
const connectedRegistry = Task__factory.connect(address, wallet);
List of available functions on Task contract
The contract supports all ERC721 methods with a few added functionality listed below:
- constructor(string
name
, stringsymbol
, addressworkerRegistry
) - Will be used to initialize the contract - createTask(string
title
, stringdescription
, intcompensation
) - Creates a new task instance to be called by Job contract - isValidTask(int
taskId
) - Checks if the task exist - isCompletedTask(int
taskId
) - Checks if the task is completed - hasEvidence(int
taskId
) - Checks if evidence has been submitted before - isCandidate(int
taskId
, addresscandidate
) - Checks if given address is indeed a candidate applying for task - isAssigned(int
taskId
) - Checks if task is assigned to anyone - tasks(int
taskId
) - Returns all information about the task - getCompensation(int
taskId
) - Returns the value of compensation for the task in wei - getAssignee(int
taskId
) - Returns the assigned address for the task - getTaskByJob(address
jobAddress
) - Returns an array for all the task owned by job - getTaskByWorkerAddress(address
workerAddress
) - Returns an array of in-progress task for a given worker address - getCandidateByTask(int
taskId
) - Returns an array of all potential candidate for a task - addCandidates(int
taskId
, addressworkerAddress
) - Adds a given candidate to a job - assignTask(int
taskId
, addressassignedTo
) - Assigns a candidate to a given task - submitEvidence(int
taskId
, stringevidence
,addressassignedTo
) - Allows the candidate to submit evidence via job contract - approveTask(int
taskId
, addressendorsedBy
) - Allows the job owner to check the evidence and accept the work - rejectEvidence(int
taskId
, addressendorsedBy
) - Allows the job owner to check the evidence and reject the work - reAssignTask(int
taskId
, addressassignedTo
) - Allow job owner to reassign the task if worker does not meet standards set
JobCreator allows us to control who can deploy new jobs. This gives us greater security as we will know exactly who posted a job. You can connect to the JobCreator contract we have deployed at 0xC784727e7dD2689fD25277236E2526d36F907313
.
Connecting to existing JobCreator contract on Ethereum
import {JobCreator__factory} from "@payrollah/payrollah-registry";
const connectedRegistry = JobCreator__factory.connect(address, wallet);
List of available functions on JobCreator contract:
- constructor(address
companyRegistry
, addressworkerRegistry
, addresstaskRegistry
) - Will be used to initialize the contract - deployNewJob(string
title
, stringdescription
) - Deploys a new job contract
Job is a smart contract which will hold the compensation for all task. It will track the sub task required for the job to be completed. when you use JobCreator to deploy a job, an address will be returned. You can connect to the address of the job.
Connecting to existing Job contract on Ethereum
import {JobCreator__factory} from "@payrollah/payrollah-registry";
const connectedRegistry = JobCreator__factory.connect(address, wallet);
List of available functions on JobCreator contract:
- constructor(address
taskRegistry
, addressjobOwner
, stringtitle
, stringdescription
) - status() - Returns status for job
- tasks(int
index
) - Return task by order of creation - collaborators(address
workerAddress
) - Check if worker is a collaborator in a job - jobOwner() - Return owner of job
- title() - Return title of job
- description() - Return description of job
- isJobTask(int
taskId
) - Check if given task is job's task - getTasks() - Return all task of this job
- addTask(string
title
, stringdescription
, intcompensation
) - Add task for this job - addCandidates(int
taskId
, addressworkerAddress
) - Adds a given candidate to this job - assignTask(int
taskId
, addressassignedTo
) - Assigns a candidate to a given task for this job - submitTask(int
taskId
, stringevidence
) - Allows the candidate to submit evidence for this job - approveTask(int
taskId
) - Allows the job owner to check the evidence and accept the work for this job - rejectEvidence(int
taskId
) - Allows the job owner to check the evidence and reject the work - reAssignTask(int
taskId
, addressassignedTo
) - Allow job owner to reassign the task if worker does not meet standards set for a task in this job - completeJob() - Allows job owner to complete the task and pay all collaborators
Different ways to get provider or signer:
import {Wallet, providers, getDefaultProvider} from "ethers";
// Providers
const mainnetProvider = getDefaultProvider();
const ropstenProvider = getDefaultProvider("ropsten");
const metamaskProvider = new providers.Web3Provider(web3.currentProvider); // Will change network automatically
// Signer
const signerFromPrivateKey = new Wallet("YOUR-PRIVATE-KEY-HERE", provider);
const signerFromEncryptedJson = Wallet.fromEncryptedJson(json, password);
signerFromEncryptedJson.connect(provider);
const signerFromMnemonic = Wallet.fromMnemonic("MNEMONIC-HERE");
signerFromMnemonic.connect(provider);
npm install
npm run test
npm run truffle <command>
This repo was made for our IS4302 Blockchain and Distributed Ledger Technologies final project!