I get error, swap not working with 1inch plugin

Hi, could I get some help, please? I’m trying to swap using 1inch plugin and it does not work, using mainnet moralis server, here’s my code:

const serverUrl = "https://nn6ulsjd1ob9.usemoralis.com:2053/server";
const appId = "LjRPQA8jLBlrSRA2UicJMyABhDWy75XCIdIzsBuN";
Moralis.start({ serverUrl, appId });

await Moralis.initPlugins();
await Moralis.enableWeb3();

I tried to change slippage up to 20 but, there was no difference

const options = {
    chain: "eth",
    fromTokenAddress: nativeAddress,
    toTokenAddress: oneInchAddress,
    amount: Number(Moralis.Units.ETH("0.01")),
    fromAddress: Moralis.User.current().get("ethAddress"),
    slippage: 1
  }

let receipt = await Moralis.Plugins.oneInch.swap(options);

The error I get is this:
3fba0833e77dfcd0fbfa27e9cda06551

Did you install the plugin on the server you are trying to do this through?

1 Like

No, I forgot thanks! I used ropsten server before, so I forgot to install it again x)

Now I’m getting these error:
4ffba2fbbdbb4e92bb5f9fb2a704f7d9

and I also get these errors a few seconds or minutes later, after clicking swap button:

The Text says this:
6a6845ce1304aa72561186a05895b3a2

Hm looks like it set the amount to 0.1 eth even though you specified 0.01. I guess try lowering it for one decimal and see if you get the pop up?

1 Like

Changed it to 0.1 eth but, I still get the same error, there is just one extra 0 in Amount here:
0b5445394a84febe3b47d076f192f49f

Yeah I am saying try lowering it to “0.001”

1 Like

Ok, yes now it works thank you @kone! I get a metamask pop up, but should it not work normally with 0.01 or 0.1 eth? or is it maybe a bug?

Yeah, that’s some unfortunate bug then I guess

1 Like

Or wait could it be doing that because you are converting it to a number maybe? Could you remove that conversion and try?

1 Like

I tried that now, I put: amount: 1000000000000000000, but, I still get the same error

The amount you put has 19 digits, which makes it 10 eth.
Just try putting amount: Moralis.Units.ETH("0.01")

I checked and normally, 18 zeros is 1 eth, no? I tried to remove some zeros and it works when I get to 0.001 eth in wei

I see. Actually there could be another reason - maybe the plugin itself already checks if you have enough eth or not instead of metamask telling you that (looking at the screenshot above you have just about 0.01 eth on the account, so you cannot swap for 0.01 because you have to pay gas as well?)

1 Like

Ok I see, I have about 0.001 eth, I get metamask pop-up but cannot confirm because of gas as you said. So that’s why when I try to swap for 0.1 it does not work because I do not have 0.1 eth, that makes sense! Thanks @kone!

1 Like