? ? 在以太坊中,賬戶擁有4個欄位:{nonce,balance,codeHash,StorageRoot},
? ? 一共分為2種賬戶:外部賬戶、合約賬戶,
? ? 外部賬戶,Externally Owned Accounts,簡稱EOA,它擁有私鑰,其codeHash為空,
? ? 合約賬戶,Contact Account,簡稱CA,它沒有私鑰,其codeHash非空,
| 比較 | 外部賬戶 | 合約賬戶 |
|---|---|---|
| 擁有私鑰 | 是 | 否 |
| codeHash內容 | 為空 | 非空 |
| 主動發起交易 | 是 | 否,只能被動發起交易 |
| 擁有余額 | 是 | 是 |
| 地址長度 | 20位元組 | 20位元組 |
? ? 判斷一個地址是否為合約地址的方法如下:
? ? //judge.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.2;
library Address {
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/328167.html
標籤:區塊鏈
下一篇:2021.10.19數字貨幣小計
