I am trying to exchange 1 USDT for some BNB. By using PancakeSwap Smart Router V3 and python web3.
example code
tokenOut = web3.to_checksum_address("0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe") # XRP
tokenIn = web3.to_checksum_address("0x55d398326f99059ff775485246999027b3197955") # USDT
weth = web3.to_checksum_address("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c") # weth
fee = 4000
recipient = wallet
deadline = int(time.time() + 6000)
qty = Wei(10**18)
min_tokens_bought = 0
tx = pancake_smart_router_contract.functions.exactInputSingle(
(
tokenIn,
weth,
fee,
recipient,
deadline,
qty,
min_tokens_bought,
0
)
)
tx_params: TxParams = {
"from": wallet_addr,
"gas": Wei(250_000),
"gasPrice": web3.eth.gas_price,
"value": Wei(0),
"nonce": web3.eth.get_transaction_count(wallet)
}
transaction = tx.build_transaction(tx_params)
signed_transaction = web3.eth.account.sign_transaction(
transaction,
private_key=private_key
)
a = web3.eth.send_raw_transaction(
signed_transaction.rawTransaction
)
However i am getting error in blockchain.
You can view the transaction in detail here
https://bscscan.com/tx/0x0a7c4d902f62e19f3d3f0581580a4bfcec48a17c99945da87442affdcad2c62e
Please help me what am I doing wrong? I also have problems with the estimate_gas function for this exchange. If you have developed similar functionality please share the correct usage code.