I am working with Truffle on a payroll smart contract that handles payments, employee addresses, etc. Right now my structure looks something like this:


pragma solidity ^0.4.19;

import './InterfacePayroll.sol';
import './EmployeeStorage.sol';
import './Token.sol';

contract Payroll is InterfacePayroll, Ownable {
using SafeMath for uint256;

//set employeeStorage to inherit methods of InterfaceEmployeeStorage
InterfaceEmployeeStorage public employeeStorage;

//set employeeToken to Token
Token public employeeToken;

modifier validAddress(address _address){
    require (_address != 0x0);

modifier higherThanZero(uint256 _uint){
    require(_uint > 0);

//contructor initializes an instance of EmployeeStorage
//Gas limit has to be raised manually
//TODO set gas limit internally
function Payroll() public{
    setEmployeeStorage(new EmployeeStorage());
    setEmployeeToken(new Token());

//set employeeStorage to contract EmployeeStorage
function setEmployeeStorage(address _newEmployeeStorage) 
onlyOwner validAddress(_newEmployeeStorage){
    employeeStorage = InterfaceEmployeeStorage(_newEmployeeStorage);

//set employeeToken to Token contract
function setEmployeeToken(address _newEmployeetoken)
onlyOwner validAddress(_newEmployeetoken){
    employeeToken = Token(_newEmployeetoken);

//Accept ETH payments
function () payable public { }

//========================= Functions
//=======Add functions
//Add employee to employee storage
function addEmployee(address _address, uint256 _monthlySalary, uint256 _startDate)
    employeeStorage.add(_address, _monthlySalary, _startDate);



So you can see that Payroll uses an instance of Employeestorage and Token. I have tested it on Remix and it seems to be working fine. My question is, how would my 2_deploy_contracts.js look like? Seems like it would simply be:


var payroll = artifacts.require("./Payroll");

module.exports = function(deployer) {

Here is my Gist with all the code.

  • 1
    From eyeballing it, yes. It appears that payroll deploys the instances it depends on so deploy is that simple. You can confirm that in Remix. Is the necessary to "Create" more than one contract to get it to work? – Rob Hitchens - B9lab Dec 24 '17 at 22:56
  • @RobHitchens yes, in Remix after compiling, the only contract I create is Payroll and all functionalities are working properly. – ApollyoN Dec 24 '17 at 23:13

If all the imports are libraries and the given contract is you main contract then use this:

var InterfacePayroll = = artifacts.require("./InterfacePayroll");
var EmployeeStorage= = artifacts.require("./EmployeeStorage");
var Token= = artifacts.require("./Token");
var Payroll = = artifacts.require("./Payroll");
module.exports = function(deployer) {
deployer.deploy(InterfacePayroll );
deployer.link(InterfacePayroll ,Payroll );
deployer.link(EmployeeStorage,Payroll );
deployer.link(Token,Payroll );
deployer.deploy(Payroll );

In short, deploy the libraries/dependencies, then link them, then deploy your favorite contract. :)

  • Don't I also need: var payroll = artifacts.require("./Payroll"); – ApollyoN Dec 26 '17 at 19:46
  • Yes you do, i missed it. – Kashish Khullar Dec 26 '17 at 20:24
  • Thank you! I am still not clear why I have to link the libraries if Payroll.sol deploys the libraries internally. – ApollyoN Dec 26 '17 at 20:28
  • how does it deploy them internally? – Kashish Khullar Dec 26 '17 at 20:33
  • If you see the setEmployeeStorage and the setEmployeeToken functions they each take a new() instance of EmployeeStorage and Token thus internally deploying them, no? – ApollyoN Dec 26 '17 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.