wallet/gettransactionbyid - Get TRON Transactio...
Retrieve detailed TRON transaction information by transaction ID including status, fees, contracts executed, and block confirmation via Dwellir RPC.
Instant Transaction Tracking
Dwellir's TRON endpoints retrieve transaction details in under 50ms with comprehensive status information. Track payments, confirmations, and smart contract executions in real-time.
Retrieves detailed information about a specific transaction using its transaction ID (hash). Essential for tracking transaction status, confirmations, and execution results.
When to Use This Method
wallet/gettransactionbyid is essential for:
- Transaction Confirmation - Check if transaction was successful and confirmed
- Payment Tracking - Monitor payment status in real-time
- Error Debugging - Analyze failed transactions and error messages
- Fee Analysis - Review bandwidth and energy consumption
- Smart Contract Results - Get contract execution results and logs
Request Parameters
Transaction ID (hash) to lookup Example: `"2668be54c278d702eebde274a58cfae3ea50c72c76a885df48c6d456d7ec38b5"`
`true` - Use Base58 address format in response `false` - Use hex address format in response
Response Body
`ret` - Execution result array with status and fees `signature` - Array of transaction signatures `txID` - Transaction identifier `raw_data` - Original transaction data `raw_data_hex` - Hex encoded transaction data `SUCCESS` - Transaction executed successfully `REVERT` - Smart contract execution reverted `UNKNOWN` - Transaction not found or pending
Implementation Examples
# Get transaction by ID
curl -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/gettransactionbyid" \
-H "Content-Type: application/json" \
-d '{
"value": "2668be54c278d702eebde274a58cfae3ea50c72c76a885df48c6d456d7ec38b5",
"visible": true
}'
# Parse transaction details
curl -s -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/gettransactionbyid" \
-H "Content-Type: application/json" \
-d '{
"value": "2668be54c278d702eebde274a58cfae3ea50c72c76a885df48c6d456d7ec38b5",
"visible": true
}' | jq '{
tx_id: .txID,
status: .ret[0].contractRet // "NOT_FOUND",
successful: (.ret[0].contractRet == "SUCCESS"),
block_number: .blockNumber,
timestamp: .blockTimeStamp,
fee: .ret[0].fee // 0,
energy_used: .ret[0].energy_usage // 0,
contract_type: .raw_data.contract[0].type,
contract_details: .raw_data.contract[0].parameter.value
}'
# Transaction monitoring script
#!/bin/bash
API_KEY="YOUR_API_KEY"
# Function to get transaction details
get_transaction() {
local tx_id=$1
curl -s -X POST "https://api-tron-mainnet.n.dwellir.com/$API_KEY/wallet/gettransactionbyid" \
-H "Content-Type: application/json" \
-d "{\"value\": \"$tx_id\", \"visible\": true}"
}
# Function to analyze transaction
analyze_transaction() {
local tx_id=$1
local tx_data=$(get_transaction "$tx_id")
# Check if transaction exists
local tx_id_response=$(echo "$tx_data" | jq -r '.txID // empty')
if [ -z "$tx_id_response" ]; then
echo "❌ Transaction not found: $tx_id"
return 1
fi
# Extract key information
local status=$(echo "$tx_data" | jq -r '.ret[0].contractRet // "UNKNOWN"')
local block_number=$(echo "$tx_data" | jq -r '.blockNumber // empty')
local timestamp=$(echo "$tx_data" | jq -r '.blockTimeStamp // empty')
local fee=$(echo "$tx_data" | jq -r '.ret[0].fee // 0')
local energy_used=$(echo "$tx_data" | jq -r '.ret[0].energy_usage // 0')
local contract_type=$(echo "$tx_data" | jq -r '.raw_data.contract[0].type // "UNKNOWN"')
echo "=== Transaction Analysis: $tx_id ==="
echo "Status: $status"
echo "Contract Type: $contract_type"
if [ -n "$block_number" ]; then
echo "✅ Confirmed in block: $block_number"
if [ -n "$timestamp" ]; then
local readable_time=$(date -d "@$((timestamp / 1000))" "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "Invalid timestamp")
echo "Time: $readable_time"
fi
else
echo "⏳ Pending confirmation"
fi
echo "Fee: $fee SUN"
echo "Energy Used: $energy_used"
# Parse contract details based on type
case "$contract_type" in
"TransferContract")
local from=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.owner_address')
local to=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.to_address')
local amount=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.amount')
local amount_trx=$(echo "scale=6; $amount / 1000000" | bc -l)
echo ""
echo "TRX Transfer Details:"
echo " From: $from"
echo " To: $to"
echo " Amount: $amount_trx TRX ($amount SUN)"
;;
"TriggerSmartContract")
local caller=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.owner_address')
local contract=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.contract_address')
local call_value=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.call_value // 0')
echo ""
echo "Smart Contract Call Details:"
echo " Caller: $caller"
echo " Contract: $contract"
echo " Call Value: $call_value SUN"
;;
esac
echo ""
}
# Function to track transaction until confirmed
track_transaction() {
local tx_id=$1
local timeout=${2:-300} # Default 5 minutes
local check_interval=${3:-5} # Default 5 seconds
echo "Tracking transaction: $tx_id"
echo "Timeout: ${timeout}s, Check interval: ${check_interval}s"
echo ""
local start_time=$(date +%s)
local end_time=$((start_time + timeout))
while [ $(date +%s) -lt $end_time ]; do
local tx_data=$(get_transaction "$tx_id")
local tx_id_response=$(echo "$tx_data" | jq -r '.txID // empty')
if [ -n "$tx_id_response" ]; then
local block_number=$(echo "$tx_data" | jq -r '.blockNumber // empty')
local status=$(echo "$tx_data" | jq -r '.ret[0].contractRet // "UNKNOWN"')
if [ -n "$block_number" ]; then
local elapsed=$(($(date +%s) - start_time))
echo "✅ Transaction confirmed after ${elapsed}s"
analyze_transaction "$tx_id"
return 0
else
echo "⏳ Transaction found in mempool, waiting for confirmation..."
fi
else
echo "🔍 Transaction not found yet, checking again..."
fi
sleep $check_interval
done
echo "⏰ Tracking timeout after ${timeout}s"
return 1
}
# Function to verify payment
verify_payment() {
local tx_id=$1
local expected_amount=$2
local expected_recipient=$3
echo "Verifying payment: $tx_id"
echo "Expected: $expected_amount SUN to $expected_recipient"
echo ""
local tx_data=$(get_transaction "$tx_id")
local tx_id_response=$(echo "$tx_data" | jq -r '.txID // empty')
if [ -z "$tx_id_response" ]; then
echo "❌ Verification failed: Transaction not found"
return 1
fi
local status=$(echo "$tx_data" | jq -r '.ret[0].contractRet // "UNKNOWN"')
if [ "$status" != "SUCCESS" ]; then
echo "❌ Verification failed: Transaction status is $status"
return 1
fi
local contract_type=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value | keys[0]')
# Check if it's a TRX transfer
local actual_amount=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.amount // empty')
local actual_recipient=$(echo "$tx_data" | jq -r '.raw_data.contract[0].parameter.value.to_address // empty')
if [ -z "$actual_amount" ] || [ -z "$actual_recipient" ]; then
echo "❌ Verification failed: Not a TRX transfer transaction"
return 1
fi
if [ "$actual_amount" = "$expected_amount" ] && [ "$actual_recipient" = "$expected_recipient" ]; then
echo "✅ Payment verified successfully"
echo " Amount: $actual_amount SUN"
echo " Recipient: $actual_recipient"
return 0
else
echo "❌ Payment verification failed"
echo " Expected amount: $expected_amount SUN"
echo " Actual amount: $actual_amount SUN"
echo " Expected recipient: $expected_recipient"
echo " Actual recipient: $actual_recipient"
return 1
fi
}
# Batch transaction analysis
batch_analyze() {
local tx_file=$1
if [ ! -f "$tx_file" ]; then
echo "Error: Transaction list file not found: $tx_file"
echo "Create a file with one transaction ID per line"
return 1
fi
echo "=== Batch Transaction Analysis ==="
echo "Processing transactions from: $tx_file"
echo ""
local total=0
local successful=0
local failed=0
local pending=0
local not_found=0
while IFS= read -r tx_id; do
# Skip empty lines
[ -z "$tx_id" ] && continue
((total++))
local tx_data=$(get_transaction "$tx_id")
local tx_id_response=$(echo "$tx_data" | jq -r '.txID // empty')
if [ -z "$tx_id_response" ]; then
echo "❌ $tx_id - NOT FOUND"
((not_found++))
else
local status=$(echo "$tx_data" | jq -r '.ret[0].contractRet // "UNKNOWN"')
local block_number=$(echo "$tx_data" | jq -r '.blockNumber // empty')
if [ -z "$block_number" ]; then
echo "⏳ $tx_id - PENDING"
((pending++))
elif [ "$status" = "SUCCESS" ]; then
echo "✅ $tx_id - SUCCESS (Block: $block_number)"
((successful++))
else
echo "❌ $tx_id - FAILED ($status)"
((failed++))
fi
fi
done < "$tx_file"
echo ""
echo "=== Summary ==="
echo "Total: $total"
echo "Successful: $successful"
echo "Failed: $failed"
echo "Pending: $pending"
echo "Not Found: $not_found"
}
# Usage examples
case "${1:-analyze}" in
"analyze")
analyze_transaction "$2"
;;
"track")
track_transaction "$2" "$3" "$4"
;;
"verify")
verify_payment "$2" "$3" "$4"
;;
"batch")
batch_analyze "$2"
;;
*)
echo "Usage: $0 {analyze|track|verify|batch} [args...]"
echo ""
echo "Commands:"
echo " analyze TX_ID - Analyze single transaction"
echo " track TX_ID [TIMEOUT] [INTERVAL] - Track until confirmed"
echo " verify TX_ID AMOUNT RECIPIENT - Verify payment"
echo " batch TX_LIST_FILE - Analyze multiple transactions"
echo ""
echo "Examples:"
echo " $0 analyze 2668be54c278d702eebde274a58cfae3ea50c72c76a885df48c6d456d7ec38b5"
echo " $0 track 2668be54c278d702eebde274a58cfae3ea50c72c76a885df48c6d456d7ec38b5 300 5"
echo " $0 verify 2668be54c278d702eebde274a58cfae3ea50c72c76a885df48c6d456d7ec38b5 1000000 TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN"
echo " $0 batch transactions.txt"
;;
esacResponse Examples
Successful TRX Transfer
{
"ret": [
{
"contractRet": "SUCCESS",
"fee": 1100
}
],
"signature": [
"c8f8f8e8d8c8b8a898887878686858484838281807060504030201..."
],
"txID": "2668be54c278d702eebde274a58cfae3ea50c72c76a885df48c6d456d7ec38b5",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"amount": 1000000,
"owner_address": "TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh",
"to_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN"
},
"type_url": "type.googleapis.com/protocol.TransferContract"
},
"type": "TransferContract"
}
],
"ref_block_bytes": "4a7b",
"ref_block_hash": "e15e44aa73bd9e15",
"expiration": 1734567890000,
"timestamp": 1734567830000
},
"blockNumber": 52895819,
"blockTimeStamp": 1734567893000
}Failed Smart Contract Call
{
"ret": [
{
"contractRet": "REVERT",
"fee": 5000
}
],
"signature": ["..."],
"txID": "a1b2c3d4e5f6789012345678901234567890123456789012345678901234567890",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"data": "a9059cbb0000000000000000000000004142b5e01c8c59a25d78acdbec2bfc7e89e5e86300000000000000000000000000000000000000000000000000000000000f4240",
"owner_address": "TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh",
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
},
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
},
"type": "TriggerSmartContract"
}
],
"ref_block_bytes": "4a7b",
"ref_block_hash": "e15e44aa73bd9e15",
"expiration": 1734567890000,
"timestamp": 1734567830000
},
"blockNumber": 52895820,
"blockTimeStamp": 1734567896000
}Transaction Not Found
{}Common Use Cases
1. E-commerce Payment Tracking
class EcommercePaymentTracker {
constructor(apiKey) {
this.analyzer = new TronTransactionAnalyzer(apiKey);
this.paymentDatabase = new Map(); // Replace with real database
}
async trackOrderPayment(orderId, txId, expectedAmount, expectedRecipient) {
try {
// Store payment attempt
this.paymentDatabase.set(orderId, {
txId,
expectedAmount,
expectedRecipient,
status: 'tracking',
createdAt: Date.now()
});
// Track transaction
const result = await this.analyzer.trackTransactionStatus(txId, 300000); // 5 min timeout
if (result.trackingStatus === 'confirmed' && result.successful) {
// Verify payment details
const verification = await this.verifyOrderPayment(orderId, result);
if (verification.verified) {
await this.fulfillOrder(orderId);
return { success: true, message: 'Payment confirmed and order fulfilled' };
} else {
await this.flagPaymentIssue(orderId, verification.reason);
return { success: false, message: verification.reason };
}
} else {
await this.handlePaymentFailure(orderId, result);
return { success: false, message: 'Payment failed or timeout' };
}
} catch (error) {
console.error(`Payment tracking error for order ${orderId}:`, error);
throw error;
}
}
async verifyOrderPayment(orderId, transactionResult) {
const payment = this.paymentDatabase.get(orderId);
const contract = transactionResult.contractDetails;
if (contract.type !== 'TRX Transfer') {
return { verified: false, reason: 'Not a TRX transfer' };
}
const amountMatch = contract.amount === payment.expectedAmount;
const recipientMatch = contract.to === payment.expectedRecipient;
return {
verified: amountMatch && recipientMatch,
reason: !amountMatch ? 'Payment amount mismatch' :
!recipientMatch ? 'Payment recipient mismatch' :
'Payment verified successfully'
};
}
async fulfillOrder(orderId) {
console.log(`✅ Fulfilling order ${orderId}`);
// Implement order fulfillment logic
}
async flagPaymentIssue(orderId, reason) {
console.log(`⚠️ Payment issue for order ${orderId}: ${reason}`);
// Implement payment issue handling
}
async handlePaymentFailure(orderId, result) {
console.log(`❌ Payment failed for order ${orderId}: ${result.message}`);
// Implement payment failure handling
}
}2. Smart Contract Execution Monitor
class SmartContractMonitor {
constructor(apiKey) {
this.analyzer = new TronTransactionAnalyzer(apiKey);
this.contractAddresses = new Set();
}
addContract(address) {
this.contractAddresses.add(address);
}
async monitorContractTransaction(txId) {
try {
const details = await this.analyzer.getTransactionDetails(txId);
if (!details.found) {
return { status: 'not_found', message: 'Transaction not found' };
}
if (details.contractDetails?.type !== 'Smart Contract Call') {
return { status: 'not_contract', message: 'Not a smart contract transaction' };
}
const contractAddress = details.contractDetails.contract;
if (!this.contractAddresses.has(contractAddress)) {
return { status: 'not_monitored', message: 'Contract not in monitoring list' };
}
return {
status: 'monitored',
successful: details.successful,
contractAddress,
caller: details.contractDetails.caller,
energyUsed: details.energyUsed,
fee: details.fee,
blockNumber: details.blockNumber,
executionResult: details.status
};
} catch (error) {
return { status: 'error', message: error.message };
}
}
}Need help? Contact our support team or check the TRON documentation.
wallet/broadcasthex
Broadcast a signed TRON transaction in hexadecimal format to the network via Dwellir's high-performance RPC endpoint.
wallet/gettransactioninfobyid
Get detailed TRON transaction information including receipt, logs, and energy/bandwidth usage via Dwellir's high-performance RPC endpoint.