# KAD（KademliaChain）账户

## 帐户类型 <a href="#types-of-account" id="types-of-account"></a>

***

#### 以太坊有两种帐户类型：

* 外部所有的帐户 (EOA) – 由任何拥有私钥的人控制
* 合约帐户 – 部署到网络上的智能合约，由代码控制。

#### 这两种帐户类型都能：

* 接收、持有和发送 KAD 和 token
* 与已部署的智能合约进行交互

## 主要区别 <a href="#key-differences" id="key-differences"></a>

***

#### **外部持有**

* 创建帐户是免费的
* 可以发起交易
* 外部所有的帐户之间只能进行以太币和代币交易
* 由一对加密密钥组成：控制帐户活动的公钥和私钥

#### **合约**

* 创建合约存在成本，因为需要使用网络存储空间
* 只能[^1]在收到交易时发送交易
* 从外部帐户向合约帐户发起的交易能触发可执行多种操作的代码，例如转移代币甚至创建新合约
* 合约帐户没有私钥。 相反，它们由智能合约代码逻辑控制

## 帐户创建 <a href="#account-creation" id="account-creation"></a>

***

当你想要创建一个帐户时，大多数库将生成一个随机的私钥。

私钥由 64 个十六进制字符组成，可以用密码加密保存。

例如：

`fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036415f`

使用椭圆曲线数字签名算法(opens in a new tab)从私钥生成公钥。 通过获取公钥 Keccak-256 哈希的最后 20 个字节并校验码前面添加 `0x`，可以为帐户获取公共地址。

下面的示例显示如何使用一种名为 Clef(opens in a new tab) 的签名工具生成一个新帐户。 Clef 是一个集成在以太坊客户端 Geth(opens in a new tab) 中的账户管理和签名工具。 `clef newaccount` 命令创建一个新的密钥对并保存在加密的密钥库中。

{% code lineNumbers="true" %}

```asm6502
> clef newaccount --keystore <path>

Please enter a password for the new account to be created:
> <password>

------------
INFO [10-28|16:19:09.156] Your new key was generated       address=0x5e97870f263700f46aa00d967821199b9bc5a120
WARN [10-28|16:19:09.306] Please backup your key file      path=/home/user/go-ethereum/data/keystore/UTC--2022-10-28T15-19-08.000825927Z--5e97870f263700f46aa00d967821199b9bc5a120
WARN [10-28|16:19:09.306] Please remember your password!
生成账户 0x5e97870f263700f46aa00d967821199b9bc5a120
```

{% endcode %}

可以通过你的私钥获取公钥，但你不能通过公钥获取私钥。 这意味着保持私人密钥的安全至关重要，如同名称所建议的 **PRIVATE**。

你需要一个私钥来签署消息和交易并输出签名。 然后其他人可以使用签名获取你的公钥，证明信息的作者。 在你的应用程序中，可以使用 javascript 库向网络发送交易。

[^1]:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kademliachain.gitbook.io/kad/kadkademliachain-zhang-hu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
