I am rying to get the address of public variable tokenContract of datatype contract but its returning the address as ''0x0000000000000000000000000000000000000000'' below is the code for the same

Smart Contract code

pragma solidity ^0.4.2;

 * The AjTokenSale contract does this and that...
 import './AjToken.sol';

contract AjTokenSale {
    address admin;
    AjToken public tokenContract;
    function AjTokenSale() public {
        //Assign an Admin
        admin = msg.sender;
        //Token contract
        //Set the Token Price


Test Code

var AjTokenSale = artifacts.require('./AjTokenSale.sol');
var AjToken  = artifacts.require('./AjToken.sol');
contract('AjTokenSale', function(accounts) {
    var tokenSaleInstance;

    it('Initializes the contract with the correct values', function() {
        return AjTokenSale.deployed().then(function(instance) {
            tokenSaleInstance = instance;
            return tokenSaleInstance
        }).then(function(address) {
            assert.notEqual(address,0x0, 'has contract address');
            return tokenSaleInstance.tokenContract();
        }).then(function(address) {
            //assert.equal(address, 0x0, 'Token contract has the address');
            assert.notEqual(address, 0x0, 'Token contract has the address');

When i am running above code test is failing on "Token contract has the address" it returns the assertion error as below,

"AssertionError: Token contract has the address: expected '0x0000000000000000000000000000000000000000' to not equal 0"

Really not sure , what is happening..

Need help..

  • I think the issue might be that you are treating instance as your address when you need to call/pass instance.address. Sep 30, 2018 at 8:15

2 Answers 2


You are not even setting the tokenContract field in your smart contract. An unset field defaults to 0. You'll have to pass the address of the tokenContract to the constructor of AJTokenSale and store it.


The type of address is String, not Number.

And this string typically stores the hexadecimal representation of a 40-digit BigNumber.

So you should change this:

assert.notEqual(address, 0x0, ...);

Either to this (string comparison):

assert(address != "0x" + "0".repeat(40), ...);

Or to this (numeric comparison):

assert(!web3.toBigNumber(address).equals(0), ...);
  • actually as per Henk , i was not assigning the value to my variable itself and when i did it worked. but as per your answer it is something that i am not able to understand..for your reference link you can see it exactly used the same way i did and it passed. Any special reason for doing the way you have shown? Sep 30, 2018 at 18:30
  • @user1576448: Of course it passed, but because every address that you receive will not be equal to 0x0. It will pass for every address - zero or not, because address is of type String and 0x0 is of type Number. I'm pretty sure that this is not the kind of test that you desire, because it will not alert you for when your address is "0x0000000000...0". Sep 30, 2018 at 18:57

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .