I'm using Brownie to try and make a basic swap on Quickswap:
from brownie import accounts, config, network, interface
def main():
"""
Runs the make_swap function on the Uniswap pair address for two particular tokens, wbtc & weth
"""
make_swap()
def make_swap():
"""
swap two particular tokens, wbtc and weth
"""
usdc = interface.WmaticInterface(config["networks"][network.show_active()]["usdc"])
weth = interface.WmaticInterface(config["networks"][network.show_active()]["weth"])
router = interface.IUniswapV2Router02(config["networks"][network.show_active()]["quickswap_router_v2_02"])
acct = accounts.add(
config["wallets"]["from_key"]
) # add your keystore ID as an argument to this call
amountIn = 0.5*10**usdc.decimals()
usdc.approve(router, amountIn, {"from": acct})
amountOutMin = 0.000383501*0.5*10**weth.decimals() #checked this from external source - quickswap
path = [usdc, weth]
deadline = 3000
tx = router.swapExactTokensForTokens(amountIn, amountOutMin, path, acct, deadline, {"from": acct, "allow_revert": True})
print("Swap made!")
return tx
The approve part goes through fine, but the actual swap gets reverted with the 'intrinsic gas too low' error:
Brownie v1.14.6 - Python development framework for Ethereum
AaveFlashloanProject is the active project.
Running 'scripts/make_swap.py::main'...
Transaction sent: 0x8900880fa866f02dcde13eedffbb862c3fa8fcc6444078e159136984146fed94
Gas price: 1.0 gwei Gas limit: 50098 Nonce: 13
WmaticInterface.approve confirmed - Block: 14979417 Gas used: 38198 (76.25%)
File "brownie/_cli/run.py", line 49, in main
return_value, frame = run(
File "brownie/project/scripts.py", line 103, in run
return_value = f_locals[method_name](*args, **kwargs)
File "./scripts/make_swap.py", line 8, in main
make_swap()
File "./scripts/make_swap.py", line 27, in make_swap
tx = router.swapExactTokensForTokens(amountIn, amountOutMin, path, acct, deadline, {"from": acct, "allow_revert": True})
File "brownie/network/contract.py", line 1676, in __call__
return self.transact(*args)
File "brownie/network/contract.py", line 1550, in transact
return tx["from"].transfer(
File "brownie/network/account.py", line 615, in transfer
exc = VirtualMachineError(e)
File "brownie/exceptions.py", line 85, in __init__
raise ValueError(exc["message"]) from None
ValueError: intrinsic gas too low
Here are my gas parameters from the brownie config file:
live:
gas_limit: auto
gas_buffer: 1.1
gas_price: auto
reverting_tx_gas_limit: true
default_contract_owner: false
I've tried adjusting gas limit to max, and gas_price to max, but doesn't seem to help.
Any ideas how to solve? And does Polygon even charge an intrinsic gas fee? I've looked on the block explorer and it looks like most similar transactions to this do go through with a gas price of 1...