swapExactTokensForTokens: AttributeError: 'NoneType' object has no attribute '_with_attr' Brownie

Viewed 139

I'm working from brownie/python trying to do a smart contract

When I try to swap from PancakeSwap on BNB testnet (https://pancake.kiemtienonline360.com) calling the function swapExactTokensForTokens from a interface it returns me "Gas estimation failed: 'execution reverted'. This transaction will likely revert." but I know probably it's nothing related to gas

Here is my approve function:

def approve_pancake(pancakeRouterv2, amount):
    account = get_account()
    wbnb = "0xae13d989dac2f0debff460ac112a837c89baa7cd"  # WBNB address
    print("Approving Pancake token...")
    pancakeRouterv2 = "0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3"  # Pancake Address Router
    erc20 = interface.IPancakeRouter01(
        wbnb)  # Access to Interfaces with WBNB address
    tx = erc20.approve(pancakeRouterv2, amount, {"from": account})  # Aprove
    tx.wait(1)

print("Approved CK")

Then I try my swapExactTokensForTokens:

def swap_pancake():
    account = get_account()
    simple_storage = BabyDoge.deploy(
        "0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526", {"from": account})  # Deploying contract - First address is for AgreggatorV3PriceFeed
    amount = Web3.toWei(0.1, "ether")
    # Path to smartcontract calling that function
    path = simple_storage.getPathForWBNBtoDAI()
    pancakeRouter = interface.IPancakeRouter01(  # IPancakeRouter01 Interface with pancake router address
        config["networks"][network.show_active()]["pancake_address"])
    # Pancake router address RAW
    pancakeRouterv2 = "0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3"
    wbnbAddress = interface.IPancakeRouter01(
        config["networks"][network.show_active()]["wbnb_token"])  # IPancakeRouter01 address with WBNB Token

    # Approving Pancake Router Address with amount
    approve_pancake(pancakeRouterv2, amount)
    transFrom = wbnbAddress.transferFrom(
        account, pancakeRouterv2, amountIn, {"from": account, "gas": 805000, "allow_revert": True})  # Testing transFrom in case was needed
    swap_tx = pancakeRouter.swapExactTokensForTokens(
        amountIn, amountOutMin, path, account, deadline, {"from": account})

    print(f"Line txt{swap_tx}")

And it gives me this error:

Transaction sent: 0x3ee8c38d5526b3c3e135cdcd0a610542c8aa59ff2f12349a769ebf8ab20b84e2
  Gas price: 10.0 gwei   Gas limit: 805000   Nonce: 546
  IPancakeRouter01.transferFrom confirmed (reverted)   Block: 15838778   Gas used: 23209 (2.88%)

  File "C:\Users\tj532\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\_cli\run.py", line 49, in main
    return_value, frame = run(
  File "C:\Users\tj532\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\project\scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File ".\scripts\pancake_swap.py", line 106, in main
    swap_pancake()
  File ".\scripts\pancake_swap.py", line 97, in swap_pancake
    transFrom = wbnbAddress.transferFrom(
  File "C:\Users\tj532\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 1693, in __call__
    return self.transact(*args)
  File "C:\Users\tj532\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 1566, in transact
    return tx["from"].transfer(
  File "C:\Users\tj532\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py", line 680, in transfer
    receipt._raise_if_reverted(exc)
  File "C:\Users\tj532\.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\transaction.py", line 420, in _raise_if_reverted
    raise exc._with_attr(
AttributeError: 'NoneType' object has no attribute '_with_attr'

I also tried without a transform and did not work

Here is my path of addresses

address constant BUSD = 0xDAcbdeCc2992a63390d108e8507B98c7E2B5584a;
address constant WBNB = 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd;

function getPathForWBNBtoDAI() public view returns (address[] memory) {
    address[] memory path = new address[](2);
    path[0] = WBNB;
    path[1] = BUSD;

    return path;
}

I also have BNB, WBNB in my account, I tried to swap manually and it worked

Could someone tell me what I'm missing? Also if you could insert a real example usage would be good

Here is the AMMS of testnet pancake: https://amm.kiemtienonline360.com/

0 Answers
Related