current position:Home>How to distinguish between contract address and ordinary account address?
How to distinguish between contract address and ordinary account address?
2022-02-03 20:46:54 【Q & A of Denglian community】
How to distinguish between contract address and ordinary account address ?
Take the answer 1:
We often need to distinguish whether an address is a contract address or an external account address , The key to distinguish is to see if there is any code associated with this address .EVM An opcode is provided EXTCODESIZE, Used to get the code size associated with the address ( length ), If it is an external account address , No code returns . Therefore, we can use the following methods to judge the contract address and external account address :
function isContract(address addr) internal view returns (bool) { uint256 size; assembly { size := extcodesize(addr) } return size > 0;}
If it is judged outside the contract , You can use web3.eth.getCode (), Or corresponding JSON-RPC Method eth_getcode.getCode () The code used to obtain the contract corresponding to the parameter address , If the parameter is an external account address , Then return to ”0x”; If the parameter is contract , Then the corresponding bytecode is returned , As shown below :
web3.eth.getCode(“0xa5Acc472597C1e1651270da9081Cc5a0b38258E3”)“0x”
web3.eth.getCode(“0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8”)
“0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056”
So we can get through getCode () What kind of address is it .
copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032046520374.html
The sidebar is recommended
- Technology weekly · why is Web3 related to blockchain
- Blockchain mainstream consensus mechanism
- Technical magic of blockchain
- Decentralized Oracle adameral blockchain data interaction Middleware
- Is it difficult to settle claims in hospital? Blockchain technology realizes "report upon hospitalization and compensation upon discharge"
- Implement the national standardization development outline and put the blockchain on a standardized path
- Understand pledge as service: opportunities and risks, current situation and future
- Talk about Web3 Decentralized work: will the Internet create human prosperity?
- Vitalik: how to improve the transaction anti censorship of the block proposer's scheme
- [Hackathon] BSV programming marathon champion plan to build a dynamic bitcoin network
guess what you like
-
Research Report on Solana: practical applications, advantages and challenges
-
A hundred flowers bloom in application, presenting the five pole pattern of North Zhejiang, Jiangsu, Shanghai and Guangdong - industrial application of China's blockchain industry development report in 2021
-
Popular science article | can Ethereum and Boca use the same address? Moonbeam "unified account" helps you achieve
-
Bloomberg 2022 encryption Outlook: the "fate" of bitcoin, Ethereum and encrypted dollar
-
Sailian blockchain education provides block chain technology training for Weichai Power
-
Sailian blockchain Education: does the school district blockchain have a future?
-
Is the development of school district block chain promising?
-
Sailian blockchain education was invited to give a training lecture on blockchain technology in Shandong science and engineering district
-
To learn blockchain technology, let's build a group school district blockchain technology
-
School district block chain technology, what do you learn? Blockchain training institutions or self-study?
Random recommended
- What exactly does blockchain learning learn? Do you need to go to blockchain training institutions?
- Review of dimitra and Morpheus AMA, global blockchain agricultural technology platform
- Bitcoin public key principle
- Blockchain application series - did
- Bitcoin series - using docker to build BTC private chain
- Bitcoin series - BTC synchronous public chain, test chain and private chain
- Bitcoin series - BTC compilation and installation
- Ethereum series - Web3 js
- Experience - deploy Ethereum private chain (POA)
- Experience part - deploying Ethereum private chain (POW)
- Ethereum series - Smart contract development and commissioning
- Ethereum series - DAPP development three swordsman
- IPFs series - combination of IPFs and blockchain
- How can the Internet of things, big data, cloud computing, blockchain and artificial intelligence be combined to promote the development of digital economy?
- The form of story telling tells you what is server, cloud deployment, virtualization, artificial intelligence, blockchain, cloud computing, big data and privacy computing
- Open source Hongmeng, metauniverse, blockchain, open source collection | alot open source science and technology festival and openharmony technology forum are in hot registration
- Bankless year-end summary: encrypted network will subvert the old power system
- The other side of Dao: bribery in the chain and the rise of dark Dao
- The first 3D chain game (CSC) of metauniverse concept seeks token in encrypted world and blockchain game
- Metauniverse 3D [NFT] arrg mobile game of metauniverse blockchain [Curtis sword]
- It is said on the Internet that three arrows bought "Adidas and gear", which is actually a fraud
- How will the global network and metauniverse affect international politics?
- GIS + blockchain, a new application scenario of geospatial data, is expected in the future
- The demand for NFT, a clothing luxury brand, has soared, and metauniverse may provide opportunities for transformation
- Curtis sword CSC coin star "Q coin mode" will be launched in January
- Adaoracle ecology and its decentralized Oracle network promote the development of blockchain
- a16z:Web3. 0 ecological panorama
- Development and application of blockchain in food industry
- Chat blockchain (III)
- Ethereum smart contract - building the basic environment
- Founder of ENS: not only Eth, to be the domain name service provider of every digital resource in the world
- A piece of land is 32 million. Why do real estate tycoons buy land in the virtual world?
- Three minutes to understand why arbitrum TVL can lead in layer2
- 13th anniversary of bitcoin white paper, 13 key knowledge points
- From didi to bitcoin, towards a new era of zero friction economy
- Randomness in bitcoin
- Blockchain private Chain NEW
- Blockchain private chain
- Blockchain game: unsustainable or is the future coming?
- Chat blockchain (IV)