I am simply trying to avoid the error:
Error: invalid address
web3
throws this error when the address to a contract is not valid.
Is there a way to catch this error ? I am using web3 in a nodejs app.
addressesweb3js
I am simply trying to avoid the error:
Error: invalid address
web3
throws this error when the address to a contract is not valid.
Is there a way to catch this error ? I am using web3 in a nodejs app.
Best Answer
There is an
isAddress()
method fromweb3.utils
, you need to use version one or following version (v1-beta, now default and latest via npm)Example:
web3.utils.isAddress(address)
Solidity Docs link: http://web3js.readthedocs.io/en/1.0/web3-utils.html?highlight=isValidAddress#isaddress