To perform an automated 1 inch transaction I use these two functions. It works well at first. Unfortunately, in the last few days I have always had the same errors:

  • Fail with error 'Return amount is not enough'

  • Warning! Error encountered during contract execution [Reverted]

    def get_api_call_data(_from_coin,_to_coin):
        global api_data
          call_data = requests.get(
          api_data = call_data.json()
        return api_data
    def one_inch_token_swap(_from_coin,_to_coin):
      global tx_hash
      web3 = Web3(Web3.HTTPProvider(eth_provider_url))
      nonce = web3.eth.getTransactionCount(base_account)
      json_data = get_api_call_data(_from_coin,_to_coin)
      data = json_data['data']
      to = json_data['to']
      value = _amount_to_exchange
      url_fees = 'https://ethgasstation.info/api/ethgasAPI.json?'
      r_fees = requests.get(url_fees)
      js_fees = json.loads(r_fees.content)
      Fastest = js_fees['fastest']
      tx = {
          'nonce': nonce,
          'to': to,  
          'value': _amount_to_exchange,         
          'from': base_account,
          'data': data,
      gas = web3.eth.estimateGas(tx)
      tx["gas"] = gas
      signed_tx = web3.eth.account.signTransaction(tx, private_key)
      tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)

what could be the cause of this error?

  • it seems to be due to the slippage percent... on some token the minimum slippage is very high, i got this error some times... but i'm interested to do the same script with the 1inch api on BSC, i'm a beginner with web3, could you give me some clue about it ? thanks ! Commented Mar 14, 2021 at 22:16

2 Answers 2


Did you "approve" _from_coin to the 1inch address?

1inch can not swap your token if you do not approve your tokens for him.

  • Yes I unlock the token directly on the 1inch site. Could this be related to eth_provider_url?
    – Laurent
    Commented Oct 22, 2020 at 19:50
  • how much is your slippage? your exchange result might be less than the minReturn due to slipage size.
    – Kami
    Commented Oct 24, 2020 at 8:18
  • I set the slippage to 5%. Is it possible to add a min return inside data?
    – Laurent
    Commented Nov 1, 2020 at 14:31

Yes, from oneinch Swap API call You get a json object were (apart the transaction constructor, tx), there are two fields called

"toTokenAmount"   : "1089293791578517848"
"fromTokenAmount" : "10000000000000000"

from were You an do your last test before signing and sending the tx. In example You can check

toTokenAmount - (toTokenAmount * ({slippage} / 100)) > minimum_desired_amount

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.