TransWikia.com

How to check validity of an address in solidity?

Ethereum Asked by manidos on November 7, 2021

Here’s a simple contract:

contract C {
    event myEvent(bool x, address y);
    address someAddress;

    function someAddressExist(){
        if(someAddress != 0){
            myEvent(true, someAddress);
        }
    }    

    function setSomeAddress(address y){
        someAddress = y;
    }
}

When I try to send a transaction to any address on the test network, except 0x1, it works. What’s so special about this address? Are there any other addresses like that?

2 Answers

web3.utils.isAddress(address)

Checks if a given string is a valid Ethereum address. It will also check the checksum, if the address has upper and lowercase letters.

Answered by Noha Abuaesh on November 7, 2021

Im not sure...what is your understanding of a valid address? In your example the argument you specify is a perfect valid address.

An address is just a variable that can hold a 20 byte value.

To answer the edited question of the OP I can link to this thread: Not all addresses created equal?. Basically some addresses hold some precompiled contracts so they will execute code if transactions are sent to them.

Answered by dragosb on November 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP