1

Is there a way to check if the ethereum address is valid in solidity? I think I might have found a way in web3js library on utils, but want to know if this method is possible on solidity.

And how can I use solidity to know the difference between account addresses and smart contract address?

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 2
    The EVM will check and fail if any value set to an address function argument is not an address. You can also use tests like `require(anAddress == address(anAddress),"Invalid address");` – Emmanuel Collin Aug 31 '20 at 08:11
  • What do you mean by a valid address? About the contract addresses you can read there https://stackoverflow.com/q/37644395/7450049 – Vitaly Migunov Aug 31 '20 at 13:19

1 Answers1

2

And how can I use solidity to know the difference between account addresses and smart contract address ?

You can use EXTCODESIZE opcode.

function isContract(address _a) public returns (bool) {
  uint size;
  assembly {
    size := extcodesize(_a)
  }
  return size > 0
}
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435