Hi I am trying to make a call to the Dai contract in the Kovan testnet using web3.js and have to set the value of web3.eth.defaultChain to 'kovan'. The docs state that the default value for web3.eth.defaultChain is 'mainnet' but it is giving me 'undefined'. I think this is also why I am getting the wrong result on querying the balanceOf method. Could someone please tell me why this is happening? Here is my code :

const Web3 = require("web3");
if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    } else {
        // set the provider you want from Web3.providers
        web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
console.log(web3.eth.defaultChain); //This returns 'undefined'
web3.eth.defaultChain = 'kovan';
var DaiContract = web3.eth.contract('ABI_HERE');
var dai = DaiContract.at('0xC4375B7De8af5a38a93548eb8453a498222C4fF2');

1 Answer 1


Your syntax (web3.eth.contract with a lower-case c) implies that you're using web3.js v0.x.

However, web3.eth.defaultChain is supported only starting from web3.js v1.x.

  • @RishabhGuha: Please accept the answer (by clicking on the V next to it) if it answers your question. May 5, 2020 at 6:39

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.