I'm trying to send transaction from one account to another in Binance Smart Chain but I get error ValueError: {'code': -32000, 'message': 'transaction type not supported'}
Here is my code
from web3 import Web3
REF_ADDRESS = '0x5...'
MY_ADDRESS = '0xe...'
MY_PKEY = 'd...'
MAX_GAS_ETHER = 0.0005
web3 = Web3(Web3.HTTPProvider('https://bsc-dataseed.binance.org/'))
balance = web3.eth.get_balance(MY_ADDRESS)
gas_price = float(web3.fromWei(web3.eth.gas_price, 'ether'))
allowed_gas = int(MAX_GAS_ETHER/gas_price)
print(web3.fromWei(balance, 'ether'))
tx = {
'from': MY_ADDRESS,
'to': REF_ADDRESS,
'value': web3.toWei(0.0001, 'ether'),
'gas': allowed_gas,
'type': 2,
'chainId': web3.eth.chain_id,
'maxFeePerGas': web3.toWei(5, 'gwei'),
'maxPriorityFeePerGas': web3.toWei(2, 'gwei'),
'nonce': web3.eth.get_transaction_count(MY_ADDRESS),
}
tx_signed = web3.eth.account.sign_transaction(tx, MY_PKEY)
tx_hash = web3.eth.send_raw_transaction(tx_signed.rawTransaction)
tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
Please help me figure up what I'm doing wrong
Well, I solved the issue by changing transaction values from
tx = {
'from': MY_ADDRESS,
'to': REF_ADDRESS,
'value': web3.toWei(0.0001, 'ether'),
'gas': allowed_gas,
'type': 2,
'chainId': web3.eth.chain_id,
'maxFeePerGas': web3.toWei(250, 'gwei'),
'maxPriorityFeePerGas': web3.toWei(2, 'gwei'),
'nonce': web3.eth.get_transaction_count(MY_ADDRESS),
}
to
tx = {
'nonce': web3.eth.get_transaction_count(MY_ADDRESS),
'to': REF_ADDRESS,
'value': web3.toWei(0.001, 'ether'),
'gas': allowed_gas,
'gasPrice': web3.eth.gas_price
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.