I have an error from web3:
Unhandled rejection Error: Given address "0x" is not a valid Ethereum address.
My question is if is there any tool that can fix my address (add checksum).
I have an error from web3:
Unhandled rejection Error: Given address "0x" is not a valid Ethereum address.
My question is if is there any tool that can fix my address (add checksum).
If you prefer a simple web version, check out EthSum:
Disclaimer: I'm the author, it's an open source tool.
With web3 you can do:
web3.toChecksumAddress('INSERT ADDRESS HERE')
It will return the address with checksum
Yes, you can.
Replcae your address in the following url of etherscan https://etherscan.io/address/{address} like this:
you want the checksum for address 0x0fd60495d705f4fb86e1b36be396757689fbe8b3
so you need to call https://etherscan.io/address/0x0fd60495d705f4fb86e1b36be396757689fbe8b3 then copy the address with valid checksum 0x0Fd60495d705F4Fb86e1b36Be396757689FbE8B3
on the loaded page.
These are the functions you're looking for: specification of the corresponding EIP and the implementation.
ethers.js also does the job. It's more lightweight than web3.js.
// Injects the checksum (via upper-casing specific letters)
ethers.utils.getAddress("0x8ba1f109551bd432803012645ac136ddd64dba72");
// '0x8ba1f109551bD432803012645Ac136ddd64DBA72'
ethers@v5
ethers.utils.isAddress(YOUR_ADDRESS)
ethers@v6
ethers.isAddress(YOUR_ADDRESS)
Adding to @3lLobo answer above on utlizing ethers.js:
ethers.js is moved from v5 to v6. So many things from v5 are no longer supported in v6 including utils. https://docs.ethers.org/v6/migrating/
https://docs.ethers.org/v6/api/address/#isAddress
Before:
ethers.utils.getAddress();
After:
ethers.getAddress();