Search code examples
pythonapicryptographybinance

How can I get my Tron(TRC20) Address from my Binance Account vie API using Python


I wanted to get my Tron(TRC20) Address from my Binance Account vie API using Python, but all i got was my (Eth) Network Address.

**This is my code below.**
rom lib2to3.pygram import Symbols
import os
import config, csv
#and then import it in your python file with
from binance.client import Client
client = Client(config.api_key, config.api_secret)

address = client.get_deposit_address(tag='', coin='USDT')\
USDTron = (address.get('TRC20'))\

Results:

print(address)
Output: {'coin': 'USDT', 'address': '0x1892e6d25a9d91dea9f9caac549261e601af97f8', 'tag': '', 'url': 'https://etherscan.io/address/0x1892e6d25a9d91dea9f9caac549261e601af97f8'}
***(I got my Eth Network Address as the output)***

print(USDTron)
Output: None
**The output was (None)**

Solution

  • I believe you might not quite understand what the python dictionary get() method does.

    According to W3schools "The get() method returns the value of the item with the specified key."

    The output from client.get_deposit_address(tag='', coin='USDT') doesnt have a key called TRC20 which is why get('TRC20') is returning None. If you used get('url') it would work and return a value since there is a key called url in the dictionary.

    Furthermore, in order to retrieve the TRC20 deposit address instead of the default ERC20 address, you need to specify an additional optional parameter which is called network as defined in the Binance API docs:

    address = client.get_deposit_address(tag='', coin='USDT', network='TRX')
    USDTron = address.get('address')
    

    The network name is found in the dropdown on the binance deposit address webpage. For TRC20 it's TRX.

    enter image description here