docs icon indicating copy to clipboard operation
docs copied to clipboard

Calling exactInputSingle returns execution reverted: STF

Open syaringan357 opened this issue 3 years ago • 14 comments

w3 = Web3(Web3.HTTPProvider(eth_local_http))
router_contract = w3.eth.contract(address=ROUTER_ADDRESS, abi=ROUTER_ABI)
DAI = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
WETH9 = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
payload = (
    WETH9,    # tokenIn
    DAI,    # tokenOut
    3000,   # fee
    ACCOUNT_ADDRESS1,   # recipient
    round(time.time()) + 60 * 20,   # deadline
    int(Web3.toWei(0.01, "ether")),    # amountIn
    0,  # amountOutMinimum
    0,  # sqrtPriceLimitX96
)
tx = router_contract.functions.exactInputSingle(payload).buildTransaction()
print(tx)

It always returns

Traceback (most recent call last):
  File "/home/wpzhou/projects/moon_eth_v3/nets.py", line 607, in <module>
    tx = router_contract.functions.exactInputSingle(payload).buildTransaction()
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/contract.py", line 1079, in buildTransaction
    return build_transaction_for_function(
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/contract.py", line 1648, in build_transaction_for_function
    prepared_transaction = fill_transaction_defaults(web3, prepared_transaction)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/_utils/transactions.py", line 121, in fill_transaction_defaults
    default_val = default_getter(web3, transaction)
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/_utils/transactions.py", line 67, in <lambda>
    'gas': lambda web3, tx: web3.eth.estimate_gas(tx),
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/eth.py", line 759, in estimate_gas
    return self._estimate_gas(transaction, block_identifier)
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/manager.py", line 170, in formatted_response
    apply_error_formatters(error_formatters, response)
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/manager.py", line 70, in apply_error_formatters
    formatted_resp = pipe(response, error_formatters)
  File "cytoolz/functoolz.pyx", line 667, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 642, in cytoolz.functoolz.c_pipe
  File "/home/wpzhou/projects/moon_eth_v3/venv/lib/python3.9/site-packages/web3/_utils/method_formatters.py", line 576, in raise_solidity_error_on_revert
    raise ContractLogicError(response['error']['message'])
web3.exceptions.ContractLogicError: execution reverted: STF

syaringan357 avatar Dec 31 '21 19:12 syaringan357

M

Yhhhuu5potyo avatar Jan 10 '22 11:01 Yhhhuu5potyo

No

Yhhhuu5potyo avatar Jan 10 '22 11:01 Yhhhuu5potyo

U

Yhhhuu5potyo avatar Jan 10 '22 11:01 Yhhhuu5potyo

H

Yhhhuu5potyo avatar Jan 10 '22 11:01 Yhhhuu5potyo

I had the same issue and the problem was, that i did not approve the token (maybe STF stands for SafeTransferFrom)

AlexField26 avatar Apr 10 '22 18:04 AlexField26

I am facing the same problem and used the uniswap app to approve the tokens i wanted to trade. But i am still facing this error. Am i missing something?

gourprabh-tt avatar Apr 15 '22 00:04 gourprabh-tt

Have the same issue. But it works for me 50/50. eg: topic author syaringan357 case works fine.

but my example with params = { tokenIn: '0x6b175474e89094c44da98b954eedeac495271d0f', tokenOut: '0xbbbbca6a901c926f240b89eacb641d8aec7aeafd', fee: 3000, amountIn: '10000000000000000000' } failed(( with Error: call revert exception

andreyLed avatar Jun 04 '22 07:06 andreyLed

Same issue here, removed the STF error by approving my contract on the token address. Still getting the gas estimation error with call revert exception

sharozx16 avatar Sep 26 '22 10:09 sharozx16

Same issue here, removed the STF error by approving my contract on the token address. Still getting the gas estimation error with call revert exception

Did you solve?

lorenzotinfena avatar Sep 30 '22 10:09 lorenzotinfena

Maybe that pool is not initialized.

shanzson avatar Nov 12 '22 07:11 shanzson

I just got this issue. So it was approved the wrong router instead of SwapRouter02.

phgoff avatar Nov 17 '22 11:11 phgoff

Which is the right routing address, can you tell me your success code?

JackGod001 avatar Dec 14 '22 23:12 JackGod001

STF 的意思是 safeTransferFrom,如果出现Fail with error 'STF',需要授权代币给合约 STF means safeTransferFrom, if Fail with error 'STF' occurs, you need to approve tokens to the contract

shaochila avatar Dec 18 '22 16:12 shaochila

STF 的意思是 safeTransferFrom,如果出现Fail with error 'STF',需要授权代币给合约 STF means safeTransferFrom, if Fail with error 'STF' occurs, you need to approve tokens to the contract

正解! Final solution!

0xbrain avatar May 24 '23 06:05 0xbrain