0

I am starting an ICO and basing my contract on OpenZeppelin. I am trying to deploy the contract using web3.js and my problem is that in the constructor I need to pass the ERC20 object of my token. I am not sure how to do that. Do I need to pass the address of the token or the ABI or what exactly? I do not find any information on this anywhere.

This is my contract constructor:

function CrowdSale(uint256 _hivePerEther, address _wallet, ERC20 _token, uint256 _openingTime, uint256 _closingTime) public {

}

My question is how to load and pass my token to the constructor when deploying using web3.js

1

yep, use the address. Your CrowdSale contract will also need to know what ERC20 tokens look like. So either paste the contract into the same CrowdSale.sol file or add import '/path/to/ERC20.sol into the same file

0

declare an ERC20 interface, pass in an address, and then you can use the interface to declare an ERC20 token from the address. Something like this:

// Standard ERC20 Token Interface
interface ERC20Token {
    function totalSupply() external view returns (uint256 _totalSupply);
    function balanceOf(address _owner) external view returns (uint256 _balance);
    function transfer(address _to, uint256 _value) external returns (bool _success);
    function transferFrom(address _from, address _to, uint256 _value) external returns (bool _success);
    function approve(address _spender, uint256 _value) external returns (bool _success);
    function allowance(address _owner, address _spender) external view returns (uint256 _remaining);

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

contract CrowdSale {

    ERC20Token token;

    constructor (uint256 _hivePerEther, address _wallet, address _token, uint256 _openingTime, uint256 _closingTime) public {
        token = ERC20Token(_token);
        ...
    }

    function getTokenBalance(address _addr) external view returns (uint256 _balance) {
         _balance = token.balanceOf(_addr);
    }
}

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.