Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to judge the account type of Yitaifang

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to judge the account type of Ethernet Square". In the course of the operation of the actual case, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

There are two types of accounts in Tai Fong, which share the same address space.

External accounts, which are controlled by public-private key pairs (human).

Contract accounts, which are controlled by the code stored in the account.

The address of the external account is determined by the public key, and the address of the contract account is determined when the contract is created.

Apart from the fact that contract accounts store codes and external accounts do not, these two types of accounts are the same for EVM. Each account has a persistent storage in the form of key-value. Among them, key and value are both 256 bits long and are called storage.

In addition, each account has an etheric balance (in "Wei"), which can be changed by sending it transactions with Ethernet coins.

Web3 implementation

You can use the web3.eth.getCode () method to determine whether an account at a given address is an external account or a contract account. This function returns the code for the specified address, and since the external account has no code, it will only return 0x, while the contract account will return a hexadecimal code string that begins with 0x. For example:

Var code = web3.eth.getCode ("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8") if (code = '0x') console.log (' external account') else console.log ('contract account') is implemented in solidity

Within the contract, you can use the EVM assembly code to get the code size at the specified address, obviously, the normal account address will return 0:

This is the end of contract EzDemo {function isContract (address addr) returns (bool) {uint size; assembly {size: = extcodesize (addr)} return size > 0;} "how to determine the account type of Ethernet Square". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report