0

I am in bsc-testnet and have 0.3 WBNB in my wallet and I try to swap 0.1 WBNB for USDT with the function swapExactTokensForTokens()

Token1 = '0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd'
Token2 = '0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee'

Pancakerouter = interface.IPancakeRouter01('0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3')

Executeswap = Pancakerouter.swapExactTokensForTokens(
        Web3.toWei(0.1, "ether"),
        0,
        [Token1,Token2],
        account,
        int(time.time()) + 10 * 600,
        {"from": account, "gas_limit": 10000000, "allow_revert": True},
    )
Executeswap.wait(1)

Here is my error and tx: VirtualMachineError: revert: TransferHelper::transferFrom: transferFrom failed https://testnet.bscscan.com/tx/0x6c8a7b802863afc92f61195dc952de1cb21d9b65b6df4205d5ad2e4a6813ed36

1 Answer 1

1

You're not approving the router to spend your WBNB. I never used brownie (or really done anything remotely complex in python, tbf x') ) so no idea how to code that exactly, but the idea is that you wanna send an approve(routerAddress, amountYouWantToSwap) transaction to the WBNB contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.