I made a function that sells a token in the BSC smartchain. However, I want to receive it in BNB directly instead of wBNB. How can I unwrap the wBNB I receive?
JavaScript
x
21
21
1
def sell_drdc(wallet_address, token_address, wallet_no):
2
if not is_approved(token_address):
3
approve(wallet_address, private_key)
4
erc20 = web3.eth.contract(token_address, abi=erc20Abi)
5
token_value = erc20.functions.balanceOf(wallet_address).call()
6
if token_value != 0:
7
pancakeswap2_txn = router.functions.swapExactTokensForTokensSupportingFeeOnTransferTokens (token_value, 0, [DRDC_Address, wbnb_contract], wallet_address, (int(time()) + 900)).buildTransaction({
8
'from': wallet_address,
9
'nonce': web3.eth.get_transaction_count(wallet_address),
10
})
11
signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key=private_key)
12
try:
13
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
14
web3.eth.waitForTransactionReceipt(tx_token, timeout=900)
15
display_success() # Just function that sends success message
16
update_text()
17
except ValueError:
18
display_error() # Just a function that sends the error
19
except UnboundLocalError:
20
sell_drdc(wallet_address, token_address, wallet_no) # Attempts to repeat if something goes wrong
21
Advertisement
Answer
I managed to see what’s wrong, It should be
JavaScript
1
2
1
swapExactTokensForETHSupportingFeeOnTransferTokens
2