1

我正在使用 brownie/python 尝试做一个智能合约

当我尝试从 BNB 测试网 ( https://pancake.kiemtienonline360.com )上的 PancakeSwap 进行交换时,从接口调用函数 swapExactTokensForTokens 它返回我“Gas 估计失败:'执行恢复'。此交易可能会恢复。” 但我知道这可能与气体无关

这是我的批准功能:

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")

然后我尝试我的 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}")

它给了我这个错误:

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'

我也尝试过没有转换但没有工作

这是我的地址路径

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;
}

我的账户里也有BNB、WBNB,我尝试手动交换,它成功了

有人能告诉我我错过了什么吗?此外,如果您可以插入一个真实的示例用法会很好

以下是测试网 pancake 的 AMMS: https ://amm.kiemtienonline360.com/

4

0 回答 0