'I keep getting an error when with tronpy trc20 token transaction - FIXED
I keep getting this error whenever I try to send an trc20 token transaction with tronpy
Traceback (most recent call last):
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/pgolphri/flask_app/app/api/routes/transaction.py", line 687, in create_token_wallet_transaction
token.token.lower()
File "/home/pgolphri/flask_app/app/tron.py", line 111, in create_token_transaction
sender_address).fee_limit(Config.TRC20_FEE_LIMIT).build()
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/tronpy/tron.py", line 210, in build
return Transaction(self._raw_data, client=self._client, method=self._method)
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/tronpy/tron.py", line 117, in __init__
self._client._handle_api_error(sign_weight)
File "/home/pgolphri/virtualenv/flask_app/3.7/lib/python3.7/site-packages/tronpy/tron.py", line 458, in _handle_api_error
raise ApiError(payload["Error"])
tronpy.exceptions.ApiError: class java.lang.NullPointerException : null
Here's the code I am using. tested it on the nile network and it works well but cant seem to get it to work on the main
def create_token_transaction(self, sender_address, priv_key, receiver_address, value, token):
private_key_raw = bytes.fromhex(priv_key.decode("utf-8"))
private_key = PrivateKey(
private_key_bytes=private_key_raw)
contract = self.token_contract(token)
decimals = contract.functions.decimals()
value = int(value * 10 ** decimals)
txn = (
contract.functions.transfer(receiver_address, value).with_owner(
sender_address).fee_limit(Config.TRC20_FEE_LIMIT).build().sign(private_key)
)
data = txn.broadcast().result()
id = txn.to_json().get("txID")
return {
"txid": id
}
Also the error occurs when trying to generate new id for the transaction from https://api.trongrid.io/wallet/getsignweight
FIXED: Basically the TRC20_FEE_LIMIT I was getting from my environment variable was a string and not a number so it was causing the error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|