简体   繁体   English

以太坊账户如何处理以太坊和 ERC20 代币的余额

[英]how does Ethereum accounts works with regards to balance of Ethereum and ERC20 tokens

I know that for Bitcoin, each address get its BTC balance from its history of transactions.我知道对于比特币,每个地址都从其交易历史中获取其 BTC 余额。 What about for ethereum?以太坊呢? How do we know the ETH balance and ERC20 token balance(s) of an Eth address?我们如何知道一个 ETH 地址的ETH 余额ERC20 代币余额

Thank you very much非常感谢你

  1. For each ethereum address, do we get its ETH balance from the ethereum world state 's database?对于每个以太坊地址,我们是否从以太坊世界 state的数据库中获取其 ETH 余额?

  2. how do we know an ethereum account's balances of each ERC20 token - is there a data field for each address containing all the erc20 contracts an account has interacted with, then the wallet checks the smart contract's balanceOf field?我们如何知道每个 ERC20 令牌的以太坊账户余额 - 每个地址是否有一个数据字段包含一个账户与之交互的所有 erc20 合约,然后钱包检查智能合约的balanceOf字段? If not, how do we know what erc20 tokens are found in an eth wallet?如果不是,我们如何知道在 eth 钱包中找到了哪些 erc20 代币?

The ERC-20 token balance of each address is stored in the storage slot of a smart contract每个地址的 ERC-20 代币余额存储在智能合约的存储槽中

The smart contract itself has an address.智能合约本身有一个地址。 So you need to query address of a smart contract -> its storage slot .所以你需要查询address of a smart contract -> its storage slot

You cannot query what tokens any address has because of the broken design of ERC-20 ( here more about the issue ).由于 ERC-20 的破损设计,您无法查询任何地址具有的令牌(此处有更多关于该问题的信息)。 Only way to know this is to build a full world indexer for Ethereum blockchain.知道这一点的唯一方法是为以太坊区块链构建一个完整的世界索引器。

actually it is not the case.实际上并非如此。 as the yellowpaper of ethereum define it, the balance is stored the same way the storage, the code, and the nonce are stored: in the world state.正如以太坊黄皮书所定义的那样,余额的存储方式与存储、代码和随机数的存储方式相同:在世界 state 中。

"The account state, σ[a], comprises the following four fields: “帐户 state,σ[a],包含以下四个字段:

nonce: A scalar value equal to the number of transactions sent from this address or, in the case of accounts with associated code, the number of contract-creations made by this account. nonce:一个标量值,等于从此地址发送的交易数量,或者对于具有关联代码的账户,等于该账户创建的合约数量。 For account of address a in state σ, this would be formally denoted σ[a]n.对于 state σ 中的地址 a,这将正式表示为 σ[a]n。

balance: A scalar value equal to the number of Wei owned by this address. balance:一个标量值,等于该地址拥有的 Wei 数量。 Formally denoted σ[a]b.正式表示为 σ[a]b。

storageRoot: A 256-bit hash of the root node of a Merkle Patricia tree that encodes the storage contents of the account (a mapping between 256-bit integer values), encoded into the trie as a mapping from the Keccak 256-bit hash of the 256-bit integer keys to the RLP-encoded 256-bit integer values. storageRoot: Merkle Patricia 树的根节点的一个 256 位 hash,它对帐户的存储内容进行编码(256 位 integer 值之间的映射),作为从 Keccak 256 位 hash 的映射编码到 trie 中256 位 integer 密钥到 RLP 编码的 256 位 integer 值。 The hash is formally denoted σ[a]s. hash 正式表示为 σ[a]s。

codeHash: The hash of the EVM code of this account—this is the code that gets executed should" codeHash:该账户的EVM代码的hash——这是被执行的代码应该”

yellowpaper黄皮书

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM