Skip to content

Transaktion erstellen

Erstellt eine neue Transaktion für Energie-Kauf oder Adress-Aktivierung.

POST /v1/transaction/new

Anfrage

Anfrage-Parameter

FeldTypErforderlichBeschreibung
external_idstringNeinOptionale externe Transaktions-ID
servicestringJaService-Typ, muss entweder "energy" oder "activate_address" sein
paramsobjectJaService-Parameter-Objekt
params.addressstringJaTRON-Wallet-Adresse (34 Zeichen)
params.energy_amountintegerJa*Zu kaufende Energie-Menge. Erforderlich wenn service="energy"
params.durationintegerJa*Dauer in Stunden (1 Stunde oder 24 Stunden). Erforderlich wenn service="energy"
params.activate_addressbooleanNeinOb die Adresse aktiviert werden soll. Optional für Energie-Service

* Nur erforderlich wenn service="energy"

bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{
  "external_id": "my-external-id-123",
  "service": "energy",
  "params": {
    "address": "TRX_ADDRESS",
    "energy_amount": 65000,
    "duration": 1
  }
}'

# Signatur berechnen
SIGNATURE=$(echo -n "${REQUEST_BODY}${API_SECRET}" | sha256sum | cut -d' ' -f1)

# API-Anfrage senden
curl -X POST "https://api.tronzap.com/v1/transaction/new" \
  -H "Authorization: Bearer ${API_TOKEN}" \
  -H "X-Signature: ${SIGNATURE}" \
  -H "Content-Type: application/json" \
  -d "${REQUEST_BODY}"
javascript
const crypto = require('crypto');
const axios = require('axios');

const apiToken = 'your_api_token';
const apiSecret = 'your_api_secret';
const requestBody = JSON.stringify({
  external_id: 'my-external-id-123',
  service: 'energy',
  params: {
    address: 'TRX_ADDRESS',
    energy_amount: 65000,
    duration: 1
  }
});

// Signatur berechnen
const signature = crypto
  .createHash('sha256')
  .update(requestBody + apiSecret)
  .digest('hex');

// API-Anfrage senden
axios({
  method: 'post',
  url: 'https://api.tronzap.com/v1/transaction/new',
  headers: {
    'Authorization': `Bearer ${apiToken}`,
    'X-Signature': signature,
    'Content-Type': 'application/json'
  },
  data: requestBody
})
.then(response => console.log(response.data))
.catch(error => console.error(error));
php
<?php
$apiToken = 'your_api_token';
$apiSecret = 'your_api_secret';
$requestBody = json_encode([
  'external_id' => 'my-external-id-123',
  'service' => 'energy',
  'params' => [
    'address' => 'TRX_ADDRESS',
    'energy_amount' => 65000,
    'duration' => 1
  ]
]);

// Signatur berechnen
$signature = hash('sha256', $requestBody . $apiSecret);

// API-Anfrage senden
$ch = curl_init('https://api.tronzap.com/v1/transaction/new');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authorization: Bearer ' . $apiToken,
  'X-Signature: ' . $signature,
  'Content-Type: application/json'
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>
python
import hashlib
import json
import requests

api_token = 'your_api_token'
api_secret = 'your_api_secret'
request_body = json.dumps({
  'external_id': 'my-external-id-123',
  'service': 'energy',
  'params': {
    'address': 'TRX_ADDRESS',
    'energy_amount': 65000,
    'duration': 1
  }
})

# Signatur berechnen
signature = hashlib.sha256((request_body + api_secret).encode()).hexdigest()

# API-Anfrage senden
headers = {
  'Authorization': f'Bearer {api_token}',
  'X-Signature': signature,
  'Content-Type': 'application/json'
}

response = requests.post(
  'https://api.tronzap.com/v1/transaction/new',
  headers=headers,
  data=request_body
)

print(response.json())

Beispiel-Anfrage für Adress-Aktivierung

bash
#!/bin/bash
API_TOKEN="your_api_token"
API_SECRET="your_api_secret"
REQUEST_BODY='{
  "external_id": "my-external-id-123",
  "service": "activate_address",
  "params": {
    "address": "TRX_ADDRESS"
  }
}'

# Signatur berechnen
SIGNATURE=$(echo -n "${REQUEST_BODY}${API_SECRET}" | sha256sum | cut -d' ' -f1)

# API-Anfrage senden
curl -X POST "https://api.tronzap.com/v1/transaction/new" \
  -H "Authorization: Bearer ${API_TOKEN}" \
  -H "X-Signature: ${SIGNATURE}" \
  -H "Content-Type: application/json" \
  -d "${REQUEST_BODY}"
javascript
const crypto = require('crypto');
const axios = require('axios');

const apiToken = 'your_api_token';
const apiSecret = 'your_api_secret';
const requestBody = JSON.stringify({
  external_id: 'my-external-id-123',
  service: 'activate_address',
  params: {
    address: 'TRX_ADDRESS'
  }
});

// Signatur berechnen
const signature = crypto
  .createHash('sha256')
  .update(requestBody + apiSecret)
  .digest('hex');

// API-Anfrage senden
axios({
  method: 'post',
  url: 'https://api.tronzap.com/v1/transaction/new',
  headers: {
    'Authorization': `Bearer ${apiToken}`,
    'X-Signature': signature,
    'Content-Type': 'application/json'
  },
  data: requestBody
})
.then(response => console.log(response.data))
.catch(error => console.error(error));

Antwort

Die Antwort liefert Details über die erstellte Transaktion.

Antwort-Felder

FeldTypBeschreibung
codeintegerAntwortcode (0 = Erfolg)
resultobjectAntwortdaten
result.idstringInterne Transaktions-ID
result.external_idstringExterne Transaktions-ID (falls angegeben)
result.paramsobjectUrsprüngliche Anfrage-Parameter
result.statusstringTransaktionsstatus (siehe Statusliste)
result.amountfloatTransaktionsbetrag
result.created_atstringErstellungszeitstempel (ISO 8601 Format)
result.hashstringTransaktions-Hash (falls abgeschlossen)

Beispiel-Antwort

json
{
    "code": 0,
    "result": {
        "id": "transaction_id",
        "external_id": "my-external-id-123",
        "params": {
            "address": "TRX_ADDRESS",
            "energy_amount": 65000,
            "duration": 1
        },
        "status": "success",
        "amount": 8.25,
        "created_at": "2024-03-22T12:00:00Z",
        "hash": "transaction_hash"
    }
}

Mögliche Fehler

FehlercodeBeschreibung
1Authentifizierungsfehler (falscher Token oder Signatur)
2Ungültiger Service oder Parameter
5Wallet nicht gefunden
6Unzureichende Mittel
10Ungültige TRON-Adresse
11Ungültige Energie-Menge
12Ungültige Dauer
24Adresse nicht aktiviert
25Adresse bereits aktiviert
500Interner Server-Fehler

Tron Energy API Documentation