I am trying to send BNB from a Trust-Wallet with a python script to my binance account.
Simple function:
def send_bnb(to_public, from_public, from_secret, amount):
nonce = web3.eth.getTransactionCount(from_public)
tx = {
'chainId': 97,
'to': to_public,
'nonce': nonce,
'value': web3.toWei( amount,'ether'),
'gas': 21000,
'gasPrice': web3.toWei('50','gwei')
}
signed_tx = web3.eth.account.signTransaction( tx, from_secret)
return web3.eth.sendRawTransaction(signed_tx.rawTransaction)
This works fine between two Trust-Wallet addresses, but fails if I try to send to my binance address.
Error is:
TypeError: Transaction had invalid fields: {'to': <to_public>}
The cause may be connected to the use of upper and lower case letters in the address, as I get the same error, if I convert the working Trust-Wallet address to lower case. But I found no hints on that so far.