How to check that an Ethereum address is valid in JavaScript
In this tutorial, we are going to learn how to verify that an Ethereum address (or any EVM address) is valid in JavaScript using the Web3 library
In this tutorial, we are going to learn how to verify that an Ethereum address (or any EVM address) is valid in JavaScript using the Web3 library.
The first thing we need to do is install the web3 JavaScript library by running:
npm install web3
Next, we need to import the library:
import Web3 from 'web3';
Now that we have our Web3
import ready, we are going to use the isAddress
utility function and pass it the address that we want to verify:
Web3.utils.isAddress(addressToVerify)
If the address is valid, this will return true
otherwise it will return false
.
For example, if we pass:
"0x9F8664D057aaf67ED8a96af49F1d715A96b2b42B"
which is a valid address, it will returntrue
"abc"
is not a valid address so it returnsfalse
And that's it! 👏
Thanks for reading this article!