1

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
    
        try:
    
          call_data = requests.get(
          f'https://api.1inch.exchange/v1.1/swap?fromTokenSymbol={_from_coin}&toTokenSymbol={_to_coin}&amount={_amount_to_exchange}&fromAddress={base_account}&slippage={slippage}&disableEstimate=true')
    
          api_data = call_data.json()
    
        except:
          logging.exception("get_api_call_data")
    
        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,         
          'gasPrice':(Fastest+100)*(100000000),
          '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?

1
  • 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 ! – Sebastien Risso Mar 14 at 22:16
0

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.