Metamask is not pop up for the Approve and Swap

Hi,
I am using moralis sdk for the approve and swap the tokens. although API is giving correct response but metamask is not poping up.

Approve Request:
{“chain”:“bsc”,“tokenAddress”:“0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3”,“fromAddress”:“0xCE8B75302AB72FC366B62557cFcbB43f3d4bd40F”,"_ApplicationId":“omited”,"_ClientVersion":“js0.0.44”,"_InstallationId":“fe876d17-2444-42f8-b98c-b502713b3e94”}

Response:
{“result”:{“status”:200,“data”:{“success”:true,“result”:{“data”:{“data”:“0x095ea7b300000000000000000000000011111112542d85b3ef69ae05771c2dccff4faa26ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”,“to”:“0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3”,“value”:“0”,“from”:“0xCE8B75302AB72FC366B62557cFcbB43f3d4bd40F”},“triggers”:[{“name”:“web3Transaction”,“data”:{“data”:“0x095ea7b300000000000000000000000011111112542d85b3ef69ae05771c2dccff4faa26ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”,“to”:“0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3”,“value”:“0”,“from”:“0xCE8B75302AB72FC366B62557cFcbB43f3d4bd40F”},“shouldAwait”:true,“shouldReturnResponse”:true,“options”:{}}]}}}}

Do you see any error in browser console when MetaMask should appear?

No error in console.
This is the subdomain URl: https://lfvtszvmvpes.moralishost.com:2053/server

MetaMask should popup before you connect to server url.
You can also add a simple code for which you would expect metamask to pop up and it doesn’t.

Hi Crtptokid,

I have solved approve token issue. but Now I am facing issue with swap. although I have enough BNB balance for the swap but still I am getting error.

Request:

{“chain”:“bsc”,“fromTokenAddress”:“0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c”,“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”:“Not enough 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c balance. Amount: 100000000000000. Balance: 0”,“error”:“Internal Server Error”}}}}

I’m not sure if it works with BNB, that token address is for WBNB, but you may also have WBNB if you mentioned about that approve part. It looks like 0x43a0C5EB1763A211Aa3c05849A617f2eE0452767 smart contract has 9 decimals, maybe you didn’t compute that amount right.

I am trying with correct amount i.e 100000000000000 because decimals for WBNB is 18 and I am trying with the amount 0.0001
In simple calculation.
100000000000000/ 10**18 = 0.0001

Take a look at https://docs.moralis.io/moralis-server/sdk-utils/moralis-units

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.