0

I start my trial token sale contract, but it keep pop out this error when i test it with truffle.

enter image description here

Here my token sale contract:

pragma solidity ^0.5.0;

import "./DappToken.sol";

contract DappTokenSale {

    address admin;
    DappToken public tokenContract;

    constructor (DappToken _tokenContract) public {
        admin = msg.sender;
        tokenContract = _tokenContract;

    }   
}

Here my test js file:

var DappTokenSale = artifacts.require('./DappTokenSale.sol');

contract('DappTokenSale', function(accounts) {
    var tokenSaleInstance;

    it('initializes the contract with the correct values', function() {
        return DappTokenSale.deployed().then(function(instance) {
            tokenSaleInstance = instance;
            return tokenSaleInstance.address
        }).then(function(address) {
            assert.notEqual(address, 0x0, "has contract address");
            return tokenSaleInstance.tokenContract();
        })..then(function(address) {
            assert.notEqual(address, 0x0, "has token contract address");
        });
    });
});

and here my contract file:

pragma solidity ^0.5.0;

contract DappToken {
    string public name = "Dapp Token";
    string public symbol = "DToken";
    string public standard = "DToken v1.0";
    uint256 public totalSupply;

    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
        );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _value
        );

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    constructor(uint256 _initialSupply) public {
        balanceOf[msg.sender] = _initialSupply;
        totalSupply = _initialSupply;
    }   

    function transfer (address _to, uint256 _value) public returns(bool success) {
        require(balanceOf[msg.sender] >= _value);
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    function approve(address _spender, uint256 _value) public returns(bool success) {
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns(bool success) {

        require (_value <= balanceOf[_from]);
        require (_value <= allowance[_from][msg.sender]);

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;

        allowance[_from][msg.sender] -= _value;

        emit Transfer( _from, _to, _value);
        return true;
    }

}

I use web3js 1.0.x, what should i do ?

1

As written, the error occurs in the migration file. You are trying to deploy the token contract without specifying the initial supply.

You can read the Truffle documentation on how to pass arguments when deploying a contract.

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.