Token-Transaktionen erstellen
Einführung
Abschnitt betitelt „Einführung“In diesem Tutorial zeigen wir, wie Sie ERC20- (Ethereum), BEP20- (Binance Smart Chain) und TRC20-Token-Transaktionen (Tron) über die Chaingateway-V2-API erstellen. Wir liefern Beispiele in verschiedenen Programmiersprachen, darunter Shell (cURL), PHP, Python und JavaScript.
Informationen zum Erhalt eines API-Keys und zur Autorisierung finden Sie im Abschnitt Erste Schritte der ChainGateway-Dokumentation.
Um Transaktionen von Ethereum, BSC oder Polygon durchzuführen, muss Ihre Adresse zu Chaingateway importiert oder mit der Chaingateway-API erstellt worden sein. Andernfalls funktioniert der Autorisierungsprozess nicht.
Informationen zum Erstellen einer Adresse finden Sie im Tutorial-Bereich
ERC20- und BEP20-Transaktionen erstellen
Abschnitt betitelt „ERC20- und BEP20-Transaktionen erstellen“Um eine Token-Transaktion auf Ethereum, Polygon (ERC20) oder Binance Smart Chain (BEP20) durchzuführen, müssen Sie eine Anfrage mit den passenden Parametern an die Chaingateway-API senden.
Parameter
Abschnitt betitelt „Parameter“- from: Die Adresse des Absenders.
- to: Die Adresse des Empfängers.
- amount: Der zu sendende Betrag.
- contractaddress: Die Contract-Adresse des Tokens.
- password: Das Passwort zur Verschlüsselung der Keystore-Datei der Absenderadresse.
Beispiel-Authorization-Header
Abschnitt betitelt „Beispiel-Authorization-Header“Ersetzen Sie YOUR_API_TOKEN durch Ihren tatsächlichen API-Token.
Codebeispiel
Abschnitt betitelt „Codebeispiel“curl --request POST \ --url https://api.chaingateway.io/v2/ethereum/transactions/erc20 \ --header 'Accept: application/json' \ --header 'content-type: application/json' \ --header 'Authorization: YOUR_API_TOKEN' \ --data '{ "from": "0xYourSenderAddress", "to": "0xRecipientAddress", "amount": "100", "contractaddress": "0xTokenContractAddress", "password": "YourPassword" }'const axios = require('axios');
const url = 'https://api.chaingateway.io/v2/ethereum/transactions/erc20';const payload = { from: '0xYourSenderAddress', to: '0xRecipientAddress', amount: '100', contractaddress: '0xTokenContractAddress', password: 'YourPassword'};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); });import requests
url = "https://api.chaingateway.io/v2/ethereum/transactions/erc20"payload = { "from": "0xYourSenderAddress", "to": "0xRecipientAddress", "amount": "100", "contractaddress": "0xTokenContractAddress", "password": "YourPassword"}headers = { 'Accept': 'application/json', 'content-type': 'application/json', 'Authorization': 'YOUR_API_TOKEN'}
response = requests.post(url, json=payload, headers=headers)print(response.json())<?phprequire 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();$response = $client->post('https://api.chaingateway.io/v2/ethereum/transactions/erc20', [ 'headers' => [ 'Accept' => 'application/json', 'content-type' => 'application/json', 'Authorization' => 'YOUR_API_TOKEN', ], 'json' => [ 'from' => '0xYourSenderAddress', 'to' => '0xRecipientAddress', 'amount' => '100', 'contractaddress' => '0xTokenContractAddress', 'password' => 'YourPassword' ]]);
echo $response->getBody();?>Der Code sollte diese Antwort zurückgeben:
{ "status": 201, "ok": true, "message": "Succesfully created transaction", "data": { "txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27" }}TRC20-Transaktionen erstellen
Abschnitt betitelt „TRC20-Transaktionen erstellen“Das Erstellen von Transaktionen für Tron-Token funktioniert nahezu identisch. Der einzige Unterschied besteht darin, dass Sie den Parameter privateKey anstelle von password angeben müssen.
Parameter
Abschnitt betitelt „Parameter“- from: Die Adresse des Absenders.
- to: Die Adresse des Empfängers.
- amount: Der zu sendende Betrag.
- contractaddress: Die Contract-Adresse des Tokens.
- privateKey: Der Private Key der Absenderadresse.
Beispiel-Authorization-Header
Abschnitt betitelt „Beispiel-Authorization-Header“Ersetzen Sie YOUR_API_TOKEN durch Ihren tatsächlichen API-Token.
Codebeispiel
Abschnitt betitelt „Codebeispiel“curl --request POST\ --url https://api.chaingateway.io/v2/tron/transactions/trc20\ --header 'Accept: application/json'\ --header 'content-type: application/json'\ --header 'Authorization: YOUR_API_TOKEN'\ --data '{ "from": "TYourSenderAddress", "to": "TRecipientAddress", "amount": "100", "contractaddress": "TTokenContractAddress", "privateKey": "YourPrivateKey"}'import requests
url = "https://api.chaingateway.io/v2/tron/transactions/trc20"payload = { "from": "TYourSenderAddress", "to": "TRecipientAddress", "amount": "100", "contractaddress": "TTokenContractAddress", "privateKey": "YourPrivateKey"}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/tron/transactions/trc20';const payload = { from: 'TYourSenderAddress', to: 'TRecipientAddress', amount: '100', contractaddress: 'TTokenContractAddress', privateKey: 'YourPrivateKey'};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/tron/transactions/trc20', [ 'headers' => [ 'Accept' => 'application/json', 'content-type' => 'application/json', 'Authorization' => 'YOUR_API_TOKEN', ], 'json' => [ 'from' => 'TYourSenderAddress', 'to' => 'TRecipientAddress', 'amount' => '100', 'contractaddress' => 'TTokenContractAddress', 'privateKey' => 'YourPrivateKey' ]]);
echo $response->getBody();?>Der Code sollte diese Antwort zurückgeben:
{ "status": 201, "ok": true, "message": "Succesfully created transaction", "data": { "txid": "0x73344d178812d4919e9002c560781f288030edf72ece88823ef1c377dfb71f27" }}