How to find out if an Ethereum address is a contract?

后端 未结 6 832
谎友^
谎友^ 2020-12-24 13:31

An address in Solidity can be an account or a contract (or other things, such as a transaction). When I have a variable x, holding an address, how can I test if it is a cont

6条回答
  •  感情败类
    2020-12-24 14:28

    This isn't something you can query from within a contract using Solidity, but if you were just wanting to know whether an address holds contract code or not, you can check using your geth console or similar with eg:

      > eth.getCode("0xbfb2e296d9cf3e593e79981235aed29ab9984c0f")
    

    with the hex string (here 0xbfb2e296d9cf3e593e79981235aed29ab9984c0f) as the address you wish to query. This will return the bytecode stored at that address.

    You can also use a blockchain scanner to find the source code of the contract at that address, for example the ecsol library as shown on etherscan.io.

提交回复
热议问题