跳转到内容

创建交易

在本教程中,我们将介绍如何使用 ChainGateway V2 API 为 Ethereum(ETH)、Binance Smart Chain(BNB)、Polygon(MATIC)、Tron(TRX)和 Bitcoin(BTC)创建交易。我们将提供多种编程语言的示例,包括 Shell(cURL)、PHP、Python 和 JavaScript。

在本教程中,我们将为原生代币 ETH BNB TRX MATIC 创建交易。要发送 TRC20、ERC20 和 BEP20 交易,请访问创建代币交易

有关获取 API key 和了解授权的信息,请参阅 Chaingateway 文档的快速入门部分。

在 Ethereum、Binance Smart Chain 或 Polygon 上进行交易时,你需要使用适当的参数向 ChainGateway API 发送请求。

  • from:发送方地址。
  • to:接收方地址。
  • amount:要发送的金额。
  • password:用于加密发送方地址 keystore 文件的密码。

YOUR_API_TOKEN 替换为你的实际 API token。

Terminal window
curl --request POST\
--url https://api.chaingateway.io/v2/ethereum/transactions\
--header 'Accept: application/json'\
--header 'content-type: application/json'\
--header 'Authorization: YOUR_API_TOKEN'\
--data '{
"from": "0xYourSenderAddress",
"to": "0xRecipientAddress",
"amount": "0.1",
"password": "YourPassword"
}'

代码应返回以下响应:

{
"status": 201,
"ok": true,
"message": "Succesfully created transaction",
"data": {
"txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27"
}
}
  • from:发送方地址。
  • to:接收方地址。
  • amount:要发送的金额。
  • privateKey:发送方地址的私钥。

YOUR_API_TOKEN 替换为你的实际 API token。

Terminal window
curl --request POST\
--url https://api.chaingateway.io/v2/tron/transactions\
--header 'Accept: application/json'\
--header 'content-type: application/json'\
--header 'Authorization: YOUR_API_TOKEN'\
--data '{
"from": "YourSenderAddress",
"to": "RecipientAddress",
"amount": "0.001",
"privateKey": "YourPrivateKey"
}'
{
"status": 201,
"ok": true,
"message": "Succesfully created transaction",
"data": {
"txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27"
}
}

要创建交易,用户需要提供地址的密码(适用于 Ethereum、Binance Smart Chain、Polygon 和 Bitcoin)或私钥(适用于 Tron)。ChainGateway 不会存储这些敏感信息。因此,用户必须将它们保存在安全的地方。如果丢失,ChainGateway 无法协助恢复,因为它无法访问这些信息。

有关获取 API key 和了解授权的信息,请参阅 ChainGateway 文档的”快速开始”部分。