Tutorial to get TRC10 or TRC20 balance of an address
To query the balance of TRC20 tokens, you need a valid Tron address. With this tutorial, you can easily query the balance of the respective Tron address. We have written a detailed tutorial for this purpose. Read more.
$tronaddress, "contractaddress" => $contractaddress) ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Authorization: " . $apikey)); # Return response instead of printing. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); # Send request. $result = curl_exec($ch); curl_close($ch); # Decode the received JSON string $resultdecoded = json_decode($result, true); # Print the Token balance to the screen echo $resultdecoded["balance"]; ?>
- Replace “YOURAPIKEY” in line 3 of above code with the API Key in your Chaingateway.io Account Panel.
- Replace “ethereumaddress” in line 4 of above code with the Tron address you want to get the balance of.
- Replace “contractaddress” in line 5 of above code with the smart contract address of the Token
- Upload the code above to your local or remote machine
- Call the script by navigating to your favorite browser and entering the URL
- After a few seconds, the script will return a balance.
Congratulations! You just checked the Token balance of an Tron address.