# 密钥管理

### FON设置Web3 <a href="#setup-web3" id="setup-web3"></a>

`web3.js`是一个 JavaScript 库，它允许我们的客户端应用程序与区块链对话。我们将 web3 配置为通过 Metamask 进行通信。

`web3.js`医生在[这里](https://web3js.readthedocs.io/en/v1.2.2/getting-started.html#adding-web3-js)

### 连接到 FSC网络 <a href="#connect-to-bsc-network" id="connect-to-bsc-network"></a>

```
    // mainnet 
     const web3 = new Web3('https://fsc-dataseed1.fonscan.io:443');
```

### 设置帐户 <a href="#set-up-account" id="set-up-account"></a>

如果 web3 的安装和实例化成功，下面应该成功返回一个随机帐户：

```
    const account = web3.eth.accounts.create();
```

### 恢复帐户 <a href="#recover-account" id="recover-account"></a>

如果您备份了您的账户私钥，您可以使用它来恢复您的账户。

```
    const account = web3.eth.accounts.privateKeyToAccount("$private-key")
```

### 完整示例 <a href="#full-example" id="full-example"></a>

```
const Web3 = require('web3');
async function main() {

    const web3 = new Web3('https://fsc-dataseed1.fonscan.io:443');
    const loader = setupLoader({ provider: web3 }).web3;

    const account = web3.eth.accounts.create();
    console.log(account);
}
```


---

# 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://docs.fonscan.io/zh_cn/bridgewallet/key.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.
