[Ethereum] TypeError: web3.eth.getTransactionCount(…).then is not a function

go-ethereumweb3js

I'm using web3 version '^0.20.6' in my node application and did following for connecting to web3 but still getting the error while calling the method getTransactionCount.

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider(INFURA_ADDRESS));

// Got error while calling the below function
web3.eth.getTransactionCount(address).then(txCount => { }); 

Error : TypeError: web3.eth.getTransactionCount(…).then is not a
function

Best Answer

web3 0.20.x is not using Promises, you need to provide a callback.

web3.eth.getTransactionCount(address, function(error, txCount) {
   // your code
}); 

ref