创建地址
在本教程中,我们将介绍如何使用 Chaingateway 为 Polygon、Binance Smart Chain、Ethereum 和 Tron 创建地址。我们将提供多种编程语言的示例,包括 Shell(cURL)、PHP(Guzzle)、Python(Requests)和 JavaScript(Axios)。 在本教程中,我们将介绍如何使用 Chaingateway 为 Polygon、Binance Smart Chain、Ethereum 和 Tron 创建地址。我们将提供多种编程语言的示例,包括 Shell(cURL)、PHP(Guzzle)、Python(Requests)和 JavaScript(Axios)。 有关获取 API key 和了解授权的信息,请参阅 Chaingateway 文档的快速入门部分。
在为基于 EVM 的区块链创建新地址时,我们需要创建一个 keystore。这是一种保护你信息安全的安全机制。keystore 会用密码进行加密。有了这种机制,你不需要在交易 payload 中发送私钥,只需要发送你的密码。仅拥有 keystore 文件或仅拥有密码的人无法访问该地址。
要创建地址,请向 Chaingateway API 发送请求。
- password:这是为新地址设定的用户自定义密码。它用于保护该地址,并在使用该地址执行交易时是必需的。务必安全地保存此密码,因为 Chaingateway 不会存储它,也无法访问它。如果密码丢失,该地址将无法访问。
Authorization Header
Section titled “Authorization Header”将 YOUR_API_TOKEN 替换为你的实际 API token。
代码示例(密码保护钱包)
Section titled “代码示例(密码保护钱包)”curl --request POST\ --url https://api.chaingateway.io/v2/ethereum/addresses\ --header 'Accept: application/json'\ --header 'content-type: application/json'\ --header 'Authorization: YOUR_API_TOKEN'\ --data '{"password":"test123"}'import requests
url = "https://api.chaingateway.io/v2/ethereum/addresses"payload = {"password": "test123"}headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'}
response = requests.post(url, json=payload, headers=headers)print(response.json())const axios = require('axios');
const url = 'https://api.chaingateway.io/v2/ethereum/addresses';const payload = { password: 'test123' };const headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'};
axios.post(url, payload, { headers }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); });<?phprequire 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();$response = $client->post('https://api.chaingateway.io/v2/ethereum/addresses', [ 'headers' => [ 'Accept' => 'application/json', 'content-type' => 'application/json', 'Authorization' => 'YOUR_API_TOKEN', ], 'json' => ['password' => 'test123']]);
echo $response->getBody();?>{ "status": 201, "ok": true, "message": "Address created", "data": { "adderess": "0x7d3bC832A0860fD882FF4C2359e10268f4E5CCf8" }}代码示例(非保护钱包)
Section titled “代码示例(非保护钱包)”curl --request POST\ --url https://api.chaingateway.io/v2/tron/addresses\ --header 'Accept: application/json'\ --header 'content-type: application/json'\ --header 'Authorization: YOUR_API_TOKEN'import requests
url = "https://api.chaingateway.io/v2/tron/addresses"headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'}
response = requests.post(url, headers=headers)print(response.json())const axios = require('axios');
const url = 'https://api.chaingateway.io/v2/tron/addresses';const headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'};
axios.post(url, {}, { headers }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); });<?phprequire 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();$response = $client->post('https://api.chaingateway.io/v2/tron/addresses', [ 'headers' => [ 'Accept' => 'application/json', 'content-type': 'application/json', 'Authorization' => 'YOUR_API_TOKEN', ]]);
echo $response->getBody();?>响应大致如下:
{ "status": 201, "ok": true, "message": "Address created", "data": { "privateKey": "59f1c6200e01a2ca9471411f10198bfa63678d0e87cc2ca30f9c4a68dee78edc", "publicKey": "040fe6e677442c36f7fdd5535ba3ff1cef0110d78363420f7e24b65298990e3467aed68b9a67e1396d84753db25b32a2fa3e1fc0a673f01638e9bcfab2d8f4ceb5", "hexAddress": "41a56a6505ffbee78eb916dd44f4846874deddaebd", "address": "TR3qx91smURF3R455V1ubqtoUsZbgqikfg" }}你应该将 privateKey 和 address 存储在你应用中一个安全的地方
要创建交易,用户需要提供地址的密码或私钥。Chaingateway 不会存储这些敏感信息。因此,用户必须将它们保存在安全的地方。如果丢失,Chaingateway 无法协助恢复,因为它无法访问这些信息。
有关获取 API key 和了解授权的信息,请参阅 Chaingateway 文档的”快速开始”部分。