1inch quote not working for custom token

I want to swap $CASH to $USDT, tried on Moralis dex.quote function as well as using postman https://api.1inch.exchange/v3.0/56/quote, the result is 500 Internal server error.
The $CASH can be swapped on pancake swap.

const quote = await dex.quote({
        chain: 'bsc',
        fromTokenAddress: '0x18950820a9108a47295b40b278f243dfc5d327b5',
        toTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
        amount: 1,
    });

even I put protocols = PANCAKESWAP_V2, still get the same error

Hi @metylbk

Your canโ€™t swap 1 Wei. For example if you try to get a quote for 1 token it will show you correct result:

const quote = await dex.quote({
        chain: 'bsc',
        fromTokenAddress: '0x18950820a9108a47295b40b278f243dfc5d327b5',
        toTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
        amount: Moralis.Units.Token("1", "18"),
    });

Here is an example:

{
  "fromToken": {
    "address": "0x18950820a9108a47295b40b278f243dfc5d327b5",
    "decimals": 18,
    "symbol": "CASH",
    "name": "Caash",
    "logoURI": "https://etherscan.io/images/main/empty-token.png",
    "isCustom": true
  },
  "toToken": {
    "symbol": "USDT",
    "name": "Tether USD",
    "decimals": 18,
    "address": "0x55d398326f99059ff775485246999027b3197955",
    "logoURI": "https://tokens.1inch.io/0xdac17f958d2ee523a2206206994597c13d831ec7.png"
  },
  "toTokenAmount": "70262871423273416",
  "fromTokenAmount": "1000000000000000000",
  "protocols": [
    [
      [
        {
          "name": "PANCAKESWAP_V2",
          "part": 100,
          "fromTokenAddress": "0x18950820a9108a47295b40b278f243dfc5d327b5",
          "toTokenAddress": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
        }
      ],
      [
        {
          "name": "JULSWAP",
          "part": 100,
          "fromTokenAddress": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
          "toTokenAddress": "0x55d398326f99059ff775485246999027b3197955"
        }
      ]
    ]
  ],
  "estimatedGas": 435342
}

Thanks, you helped me a lot.
To correct, we should call .toString():

const quote = await dex.quote({
        chain: 'bsc',
        fromTokenAddress: '0x18950820a9108a47295b40b278f243dfc5d327b5',
        toTokenAddress: '0x55d398326f99059ff775485246999027b3197955',
        amount: Moralis.Units.Token("1", "18").toString(),
    });
1 Like

Btw, I have a question about gas fee.
I calculate by this formula:
gas fee = estimatedGas * 20 / 10**9. (BNB).
As I search the average gas price unit is 20 gwei.
Is it just fine? I just want to show the estimated gas fee for user.

You donโ€™t need to use .toString() for Moralis.Units.Token() because itโ€™s a bignumber, itโ€™s not a number

It should work. Try to check a transaction fee with approved tokens

As I print out the Moralis.Units.Token(), it is an object, not a big number.

without .toString(), we get this error:

Moralis.Units.Token("1", "18") + 0 may work fine too

1 Like