Metamask is not pop up for the Approve and Swap

In the amount field we need to pass the value of amount we want to swap not the value of the token we want to receive. correct?

as per the link I am doing in the right way. as I am trying 0.0001 and 18 decimals and that is equal to 100000000000000
so, what is wrong in the request?

Absolutely right, the problem is that you are trying to swap tokens you don’t have.

Your wallet has only PDX tokens

WBNB - is an ERC20 token wrapped BNB, it has own smart contract and address 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c

BNB is a native crypto without contract address(for 1inch you can use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE )

1 Like

In my wallet I have both the BNB and PDX.

I have tried with given contract address.
Request:

{ā€œchainā€:ā€œbscā€,ā€œfromTokenAddressā€:ā€œ0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeEā€,ā€œtoTokenAddressā€:ā€œ0x43a0c5eb1763a211aa3c05849a617f2ee0452767ā€,ā€œamountā€:100000000000000,ā€œfromAddressā€:ā€œommitedā€,ā€œslippageā€:1,"_ApplicationId":ā€œC0x6JlYQmzWQ1AO9Lnr2kCDyJGVApfyUJErEGrT9ā€,"_ClientVersion":ā€œjs0.0.68ā€,"_InstallationId":ā€œ1f2476fd-514c-4f11-bc5d-86ce541dae48ā€}

Response:

{ā€œresultā€:{ā€œstatusā€:200,ā€œdataā€:{ā€œsuccessā€:true,ā€œresultā€:{ā€œstatusCodeā€:500,ā€œmessageā€:ā€œcannot estimateā€,ā€œerrorā€:ā€œInternal Server Errorā€}}}}

did you try to change from PDX to BNB?

Yes Tried both the option and getting

{ā€œresultā€:{ā€œstatusā€:200,ā€œdataā€:{ā€œsuccessā€:true,ā€œresultā€:{ā€œstatusCodeā€:500,ā€œmessageā€:ā€œcannot estimateā€,ā€œerrorā€:ā€œInternal Server Errorā€}}}}

Hey @bullish

Works fine for me:

const quote = await Moralis.Plugins.oneInch.quote({
          chain: "bsc", // The blockchain you want to use (eth/bsc/polygon)
          fromTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // The token you want to swap
          toTokenAddress: "0x43a0c5eb1763a211aa3c05849a617f2ee0452767", // The token you want to receive
          amount: 100000000000000
        });
        console.log(quote);

I just want to say that sometimes it will return you deifferrent error messages like ā€œInternal errorā€ because of a small amount to swap.

For example:
amount: 10000 - { ā€œstatusCodeā€: 500, ā€œmessageā€: ā€œInternal server errorā€ }
amount: 100000000000000 - works fine

Also you can check returns from 1inch swagger https://api.1inch.exchange/swagger/binance/#/Swap/SwapFactoryCommonController_getQuote

Issue is with swap not with quote endpoint.

Increase slippage. For me it showed correctly with slippage 10

Hi Yomoo,

Can you please paste the request here, which you are trying at your end?

async function inch() {
        await Moralis.initPlugins();
        const swap = await Moralis.Plugins.oneInch.swap({
          chain: "bsc", // The blockchain you want to use (eth/bsc/polygon)
          fromTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // The token you want to swap
          toTokenAddress: "0x43a0c5eb1763a211aa3c05849a617f2ee0452767", // The token you want to receive
          amount: 100000000000000,
          fromAddress: "0xCE8B75302AB72FC366B62557cFcbB43f3d4bd40F", // Your wallet address
          slippage: 10
        });
      }

In fromAddress was my address and it popped up metamask :man_mechanic:

As I mentinoned before, you can check the 1inch API swap

Hi Yomoo,

Above request is working fine with my wallet address but when I am trying for inverse option i.e. trying to swap 200 PDX to BNB it is throwing 500 error.

here is the request:

{
	"chain": "bsc",
	"fromTokenAddress": "0x43a0c5eb1763a211aa3c05849a617f2ee0452767",
	"toTokenAddress": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
	"amount": 200000000000,
	"fromAddress": "omitted",
	"slippage": 20,
	"_ApplicationId": "C0x6JlYQmzWQ1AO9Lnr2kCDyJGVApfyUJErEGrT9",
	"_ClientVersion": "js0.0.68",
	"_InstallationId": "1f2476fd-514c-4f11-bc5d-86ce541dae48"
}

Also for this endpoint oneInch.hasAllowance is not behaving correctly. although I have approved the token it is giving false and sometimes true

I checked your logs. You have called hasAllowance for different token_addresses and wallet_addresses

I’ve tried to figure out the problem… but without any success. If you try to get this data from 1inch swagger you will recieve the same error, so the problem is on 1inch side. We can’t really help you with it :cry:

But it will work correctly for wbnb. I guess the problem is because of wrapping the bnb