andelf / tronpy

TRON Python Client Library.
MIT License
204 stars 96 forks source link

ABI error when using HTTPProviver over just nile network #124

Closed 30ThreeDegrees closed 6 months ago

30ThreeDegrees commented 8 months ago

Hi there,

I am using this code to find a usdt balance of a wallet

from tronpy import Tron
from tronpy.providers import HTTPProvider

client = Tron(network="nile")

# cntr = client.get_contract("THi2qJf6XmvTJSpZHc17HgQsmJop6kb3ia")

# print(dir(cntr.functions))

# client = Tron(network="nile")

cntr = client.get_contract("TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj")

tron_account_address = "THYkuRwPKuSM4xbfoYqg8Nyn5UAw5kAVVR"

usdt_balance = cntr.functions.balanceOf(tron_account_address)

print(f"USDT Balance of {tron_account_address}: {usdt_balance / 10**6} USDT")

RESPONSE: USDT Balance of THYkuRwPKuSM4xbfoYqg8Nyn5UAw5kAVVR: 50000.0 USDT

And this works fine but the moment I go to use trongrid creds I get an error saying I cant call a contract without an ABI

from tronpy import Tron
from tronpy.providers import HTTPProvider

client = Tron(
    HTTPProvider(api_key="insert_key"), network="nile"
)

cntr = client.get_contract("TXLAQ63Xg1NAzckPwKHvzw7CSEmLMEqcdj")

tron_account_address = "THYkuRwPKuSM4xbfoYqg8Nyn5UAw5kAVVR"

usdt_balance = cntr.functions.balanceOf(tron_account_address)

print(f"USDT Balance of {tron_account_address}: {usdt_balance / 10**6} USDT")

RESPONSE: raise ValueError("can not call a contract without ABI") ValueError: can not call a contract without ABI

Is anyone able to give me a little bit of guidance on whats happening here without the trongrid api key it works fine but with trongrid its no longe fetching the abi on its own?

MrNaif2018 commented 6 months ago

Works for me without the api key. Maybe your key is invalid?

MrNaif2018 commented 6 months ago

HTTPProvider by default uses mainnet trongrid, but when using network="nile" it doesn't even use trongrid at all. No key is required for testnet