When I do, for example print(10 * (10**18))
, there is no problem, but when I change the first number for a variable, for example, print(amount * (10 ** 18))
I get a memory error , even though it is amount
worth it 1
.
Code:
Function 1:
currencies = {'bnb': 18, 'urub': 8}
def to_wei(amount:int, currency:str):
decimals = currencies[currency.lower()]
return amount * (10 ** decimals)
Function 1 is called inside function 2:
async def transfer_bnb(_from=None, to=None, key=None, amount=0):
print(uwutils.to_wei(amount, "BNB"))
try:
estimated_gas = w3.eth.estimate_gas({
'nonce': w3.eth.get_transaction_count(_from),
'gasPrice': w3.eth.gas_price,
'to': to,
'from': _from,
'value': uwutils.to_wei(amount, "BNB")
})
signed_txt = w3.eth.account.sign_transaction({
'nonce': w3.eth.get_transaction_count(_from),
'gasPrice': w3.eth.gas_price,
'gas': estimated_gas,
'to': to,
'from': _from,
'value': uwutils.to_wei(amount, "BNB")
}, key)
w3.eth.send_raw_transaction(signed_txt.rawTransaction)
return {'error': False}
except ValueError:
return {'error': True, 'message':'Not enough funds'}
Function 2 is called inside an asynchronous function:
async def routine(check_var, amount_entry, address_entry, account):
currency = check_var.get()
if currency == 'NONE':
pass
elif currency == 'BNB':
amount = amount_entry.get()
reciever = address_entry.get()
if w3.toChecksumAddress(reciever):
print(await tx.transfer_bnb(_from=account.public_key, to=reciever, key=account.private_key,
amount=amount))
else:
showerror("Error", "Wrong address")
elif currency == 'URUB':
amount = amount_entry.get()
reciever = address_entry.get()
if w3.toChecksumAddress(reciever):
print(await tx.transfer_urub(_from=account.public_key, to=reciever, key=account.private_key,
amount=amount))
else:
showerror("Error", "Wrong address")
check_var is a tkinter string variable, and the inputs are common tkinter inputs as well.
Finally the routine is executed in a button event:
def send_button_click():
loop = asyncio.get_event_loop()
loop.run_until_complete(routine(check_var=check_var, amount_entry=amount_entry, address_entry=address_entry, account=account))
I just found the solution to this problem, it turns out that tkinter.Entry.get() returns a string and I forgot to convert it to integer. So it was storing trillions of characters.
Since each character represents a byte, having 1 trillion of them takes up 10 to the power of 18 bytes, which is the same as 1 million terabytes.