钱包管理
在 Chaingateway 上开始使用钱包
Section titled “在 Chaingateway 上开始使用钱包”Chaingateway 提供两种生成钱包的方法:密码保护钱包和非安全钱包。下面我们描述这两种方法、它们的安全影响以及使用示例。
1. 密码保护钱包(推荐)
Section titled “1. 密码保护钱包(推荐)”如果你在向 /api/v2/{blockchain}/addresses 发起的请求中提供了 password 请求体参数,生成的钱包的私钥将以加密格式安全存储。
- 私钥使用你的密码以及额外的内部加密机制进行加密。
- 发送交易时,你提供的是
password而不是私钥。 - 这种方法通过确保私钥永远不会在 API 请求中暴露来提高安全性。
- 更新密码:使用
UPDATE /api/v2/{blockchain}/addresses/{address},并附带参数old_password和new_password。 - 导出私钥:使用
POST /api/v2/{blockchain}/addresses/export/{address}来获取你的私钥(需要密码)。
::: danger 请妥善保管你的密码 我们绝不会在我们的应用程序中存储私钥或密码——无论是在我们的数据库中,还是在我们的日志或异常处理机制中。如果你丢失了密码,我们无法恢复你钱包的私钥。 :::
curl --request POST \ --url https://app.chaingateway.io/api/v2/ethereum/addresses \ --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "password": "architecto"}'<?php$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'https://app.chaingateway.io/api/v2/ethereum/addresses');curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(["password" => "architecto"]));curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer YOUR_SECRET_TOKEN', 'Content-Type': 'application/json']);$response = curl_exec($ch);curl_close($ch);echo $response;fetch('https://app.chaingateway.io/api/v2/ethereum/addresses', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_SECRET_TOKEN', 'Content-Type': 'application/json' }, body: JSON.stringify({ password: 'architecto' })}).then(response => response.json()).then(data => console.log(data));import requestsheaders = { 'Authorization': 'Bearer YOUR_SECRET_TOKEN', 'Content-Type': 'application/json'}data = {"password": "architecto"}response = requests.post('https://app.chaingateway.io/api/v2/ethereum/addresses', headers=headers, json=data)print(response.json())curl --request POST \ --url https://app.chaingateway.io/api/v2/ethereum/transactions \ --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "from": "0xSenderAddress", "to": "0xRecipientAddress", "amount": "100", "password": "password"}'2. 非安全钱包(请谨慎使用)
Section titled “2. 非安全钱包(请谨慎使用)”如果你在地址创建请求中未提供密码,私钥将直接在响应中返回。这意味着私钥必须由你负责安全地存储和管理。
::: danger 仅用于非永久性钱包 由于私钥包含在响应中,你有责任安全地存储和保护它。我们强烈建议改用密码保护钱包。如果有人获得了你的私钥,他们就可以控制钱包中的所有资金。 :::
- 私钥在 API 响应中暴露,如果被截获则容易受到攻击。
- 如果攻击者获得私钥,他们就可以完全控制该钱包。
- 此方法应仅用于临时钱包或一次性地址。
curl --request POST \ --url https://app.chaingateway.io/api/v2/tron/addresses \ --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \ --header 'Content-Type: application/json'<?php$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'https://app.chaingateway.io/api/v2/tron/addresses');curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(["activated" => true]));curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer YOUR_SECRET_TOKEN', 'Content-Type': 'application/json']);$response = curl_exec($ch);curl_close($ch);echo $response;fetch('https://app.chaingateway.io/api/v2/tron/addresses', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_SECRET_TOKEN', 'Content-Type': 'application/json' }, body: JSON.stringify({ activated: true })}).then(response => response.json()).then(data => console.log(data));import requestsheaders = { 'Authorization': 'Bearer YOUR_SECRET_TOKEN', 'Content-Type': 'application/json'}data = {"activated": True}response = requests.post('https://app.chaingateway.io/api/v2/tron/addresses', headers=headers, json=data)print(response.json())curl --request POST \ --url https://app.chaingateway.io/api/v2/ethereum/transactions \ --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "from": "0xSenderAddress", "to": "0xRecipientAddress", "amount": "100", "password": "password"}'