I have been looking at a tutorial from DappUniversity about Web3... on the introductory video, I have completed all stages fine, but when getting to retriving account balance information from the mainnet ( i picked a random account from the Etherscan.io) it doesn't retrieve it.

I get an error like this when looking at the balance on its own ---|> web3.eth.getBalance(address, (err, bal) => { balance = bal }) the respond is 'undefined' and does not return a account value in Wei...

I tried getting to read the balance error through --|> web3.eth.getBalance(address)

that returns the following: >>>

> web3.eth.getBalance(address)
Promise {
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] } }
> (node:9060) UnhandledPromiseRejectionWarning: Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (C:\Users\User\node_modules\web3-core-helpers\src\errors.js:42:16)
    at XMLHttpRequest.request.onreadystatechange (C:\Users\User\node_modules\web3-providers-http\src\index.js:87:32)
    at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\User\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (C:\Users\User\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\User\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (C:\Users\User\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
(node:9060) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9060) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

what can i do to solve this issue!

1 Answer 1


web3.eth.getBalance(address) returns a promise which will only either return an error or the balance once the transaction is mined.

function getBalance(){ var balance; web3.eth.getBalance(address, (err, bal) => { balance = bal }) return balance; }

the case above will return undefined because the function already returned the balance before the bal was retrieved and assigned to balance.

async function getBalance(){ var balance; await web3.eth.getBalance(address, (err, bal) => { balance = bal }) return balance; }

With regards to the error UnhandledPromiseRejectionWarning: Error: Invalid JSON RPC response: "" Does it occur while calling getBalance()? It might be helpful to post a more detailed code also to better help resolve this error.

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.