Truffle v5.0.5 (core: 5.0.5)
Solidity v0.5.0 (solc-js)
Node v10.15.1

ReferenceError: address is not defined.

const ApprovalContracts = artifacts.require('../../contracts/ApprovalContracts.sol'); // Pulls in my smart contract // the accounts are the 10 dummie ones
// the require pulls in the smart contract // the artifacts pulls in our code

contract ('ApprovalContracts', function (accounts) { // These are the accounts stored locally in the server the address
    //tests in javascript part of the contract //setup a contract and getting back the approver //takes a deposit im going to look and see what the balance is
    it('initiates contract', async function() { 
        const contract = await ApprovalContracts.deployed();
        const approver = await contract.approver.call(); 
        assert.equal(approver, 0xc7780C9521C2C2abED69f0D65BEbF9794C55ae94, "approvers don't match");

    it('takes a deposit', async function() {
        const balance = await web3.eth.getBalance(address.contract);  -----> ReferenceError: address is not defined
        const expected = web3.utils.toBN(1e+18);
        assert.equal(balance.toString(), expected.toString(), "amount did not match");

Any advice I would be much appreciated.

const balance = await web3.eth.getBalance(address.contract);
  • I dont understand. This is just a test code where is your actual code, what does deposit do? You cant show us a failed test case and ask what wrong?
    – haxerl
    Commented Mar 15, 2019 at 1:25

3 Answers 3


You have two problems:

  • web3.eth.getBalance() returns an promiEvent object, to obtain the expected value you need to await for it
  • Javascript doesn't support large numbers, so values are wrapped in BN objects, and assert doesn't know how to compare those objects against numbers

One solution is converting BN objects to strings to compare them.

const balance = await web3.eth.getBalance(contract.address);
const expected = web3.utils.toBN(1e+18);
assert.equal(balance.toString(), expected.toString(), "amount did not match");
  • 1
    Thank you, I've been trying to fix this for a while.I got the error unfortunately. Error: Provided address "undefined" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted. Im having serious issues with out to make the rite corrections on code. Is there a way I can solve these challenges, or some kind of useful website
    – D6ix
    Commented Mar 16, 2019 at 1:34
  • The only address used is contract.address, check the output of console.log(contract.address);. Unless contract is incorrectly initialized it should be a valid address. You can edit your question to add more details, like the contracts used and any other thing required to reproduce your error. Otherwise my answer is just try to guess.
    – Ismael
    Commented Mar 16, 2019 at 3:23

FWIW, I had the exact same issue and got my test to pass like this:

// Truffle v5.1.23 (core: 5.1.23)
// Solidity - ^0.4.18 (solc-js)
// Node v12.14.1
// Web3.js v1.2.1

contract('ApprovalContract', function(accounts) {


  it('takes a deposit', async function () {
    const contract = await ApprovalContract.deployed();
    const balance = 1e+18;
    const expected = web3.utils.toBN(1e+18);
    await contract.deposit(accounts[1], {
      value: balance, from: accounts[0]
    assert.equal(balance.toString(), expected.toString(), "amount did not match");


I'm a total blockchain noob and am JUST starting to ramp up on it, so I can't say my test represents a real-world blockchain use case. But things pass.

Also, this code is from a lynda.com Ethereum course: it's good but it's also almost two years old at the time of this comment and has only been updated once since then. So as that tutorial says to do an npm install -g truffle, I'm assuming that the tutorial was using a truffle version older than the version we downloaded while going through things, and that caused enough conflict for the tests to initially fail.


const balance = await web3.eth.getBalance(address.contract);

change this to

const balance = await web3.eth.getBalance(contract.address);

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.