1

I have Geth in full node on my server and I want to get my USDT balance with web3.py.

Here is my Code:

from web3 import Web3
from ethtoken.abi import EIP20_ABI

w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))
tether_contract_address = Web3.toChecksumAddress('0xdac17f958d2ee523a2206206994597c13d831ec7')
contract = w3.eth.contract(tether_contract_address, abi=EIP20_ABI)
amount = contract.functions.balanceOf(Web3.toChecksumAddress(w3.eth.coinbase)).call()

But I get this result:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/web3/contract.py", line 1372, in call_contract_function
    output_data = decode_abi(output_types, return_data)
  File "/usr/local/lib/python3.9/dist-packages/eth_abi/abi.py", line 96, in decode_abi
    return decoder(stream)
  File "/usr/local/lib/python3.9/dist-packages/eth_abi/decoding.py", line 118, in __call__
    return self.decode(stream)
  File "/usr/local/lib/python3.9/dist-packages/eth_utils/functional.py", line 45, in inner
    return callback(fn(*args, **kwargs))
  File "/usr/local/lib/python3.9/dist-packages/eth_abi/decoding.py", line 164, in decode
    yield decoder(stream)
  File "/usr/local/lib/python3.9/dist-packages/eth_abi/decoding.py", line 118, in __call__
    return self.decode(stream)
  File "/usr/local/lib/python3.9/dist-packages/eth_abi/decoding.py", line 186, in decode
    raw_data = self.read_data_from_stream(stream)
  File "/usr/local/lib/python3.9/dist-packages/eth_abi/decoding.py", line 293, in read_data_from_stream
    raise InsufficientDataBytes(
eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes.  Only got 0 bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/web3/contract.py", line 1105, in call
    return call_contract_function(
  File "/usr/local/lib/python3.9/dist-packages/web3/contract.py", line 1394, in call_contract_function
    raise BadFunctionCallOutput(msg) from e
web3.exceptions.BadFunctionCallOutput: Could not transact with/call contract function, is contract deployed correctly and chain synced?

Also, my Geth synchronization is always between 50 and 100:

> eth.syncing.highestBlock - eth.syncing.currentBlock
62
1
  • 1
    You need to wait until eth.syncing is false. Your node is not fully synced. Mar 31, 2021 at 12:53

1 Answer 1

-1

you have to go to the ethereummain net and copy the abi of USDT and then paste it in your code and assign it to abi variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.