Payroll Smart Contract on Ethereum

N F
Coinmonks
3 min readMar 2, 2018

--

In this post we’ll go over a Payroll smart contract written in Solidity using Truffle and Open Zeppelin. You can find the repo here.

Let’s make sure you have Truffle installed globally:

Clone my repo to your local machine and install:

You can now use Truffle develop to compile, migrate, and run the tests:

Ok, enough of that, let’s look at some code.

The contract follows an interface approach similar to Zeppelin’s ERC20 standard in which an interface contract is defined. In our case the Payroll interface is given by:

You can see that we have all the functions necessary to manage employees and payments. Now, let’s look at the main contract: Payroll.sol.

Payroll.sol has three imports:

which allow to set the Storage variables:

EmployeeStorage.sol defines the employee structure:

EmployeeToken.sol is a simple ERC20 standard contract:

The constructor for Payroll.sol is given by:

which simply sets the employee storage and the employee token. The contract owner can now manage the employees through any of the functions defined in InterfacePayroll.sol. Employees can request to be payed for a given pay period by calling:

Payroll.sol also has several events for dapp watching:

Right now the pay period is set to be simply an uint , but it could easily be set to an actual time frame as specified by the owner.

That’s it! If you would rather work on this contract in Remix, I set up a Gist you can use.

Get Best Software Deals Directly In Your Inbox

Thank you very much for reading this post! If you found this post useful please clap on this article and make sure to follow me for more regular content, also check out my Github as I regularly post sample code and projects. If you have any questions feel free to reply below this post or shoot me an email.

Happy coding!

--

--