I need to use the functions of the ERC20 contract in another contract.

The ERC20 contract is from the openZeppelin contract library. I found the following code on a website:

import "../../node_modules/zeppelin-solidity/contracts/token/ERC20/ERC20.sol"; 

contract Escrow is Ownable { 
    ERC20 public currency; 
    address public collectionAddress;

    function Escrow(ERC20 _currency, address _collectionAddress) public { 
        currency = _currency; 
        collectionAddress = _collectionAddress; 

In this code, ERC20 instance is passed as an argument to the constructor of Escrow. That means that the ERC20 instance is stored in the Escrow contract's state variable at the time of the deployment of the Escrow contract.

I want to know how to write the deployment code for passing one contract instance as an argument to the constructor of another contract in truffle.

Also, should the ERC20 contract be deployed before the Escrow contract in Truffle or can both the contracts be deployed together?

If so, then what would the deployment script in truffle look like ?

  • I think passing the contrat itself is not possible. However, you can pass the contract address Commented Nov 22, 2018 at 12:15
  • even I think so.... but the code (which I found on the website) is apparently tested..... Commented Nov 22, 2018 at 12:20

1 Answer 1


Never tried it before, seems it is possible.

Migration script:

module.exports = function (deployer) {
    deployer.deploy(TestCoin).then(x => {
        deployer.deploy(Escrow, x.address, collectionAddress)

TestCoin is ERC20 token:

pragma solidity ^0.4.24;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; 
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol"; 

contract TestCoin is ERC20, ERC20Detailed {

    uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals()));

    constructor() public ERC20Detailed("TestCoin", "TC", 18) {
        _mint(msg.sender, INITIAL_SUPPLY);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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