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
)
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
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
But it will work correctly for wbnb. I guess the problem is because of wrapping the bnb