Edgar Papa Maduna
Edgar Papa Maduna

Reputation: 31

How to check if Ethereum address is valid in solidity?

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?

Upvotes: 2

Views: 4029

Answers (1)

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83546

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
}

Upvotes: 2

Related Questions