I was wondering if there's a PancakeSwap API, that allows me to swap BNB for a token, and if it isn't possible, can I do it with Binance Smart Chain's API?
Thank you!
I was wondering if there's a PancakeSwap API, that allows me to swap BNB for a token, and if it isn't possible, can I do it with Binance Smart Chain's API?
Thank you!
pancakeswap currently doesn't have APIs or sdk as Uniswap sdk. Best solution is connect to binance smart chain and connect to the pancakeswap router contract through web3.
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
This is the function for swap tokens. You can refer the uniswap doc to get more information.
There's an API which allows you to find the best DEX on different blockchains, including BSC, and allows you to specify the DEX you want by excluding all of the other ones.
Here's a link to the API specification: https://0x.org/docs/api
An example you could type into the browser is: https://bsc.api.0x.org/swap/v1/quote?buyToken=BUSD&sellToken=BNB&sellAmount=1000000000000000000&excludedSources=BakerySwap,Belt,DODO,DODO_V2,Ellipsis,Mooniswap,MultiHop,Nerve,SushiSwap,Smoothy,ApeSwap,CafeSwap,CheeseSwap,JulSwap,LiquidityProvider
This URL converts 1 BNB into BUSD on only Pancakeswap V1 and Pancakeswap V2.
You can also integrate this into a smart contract.
Hope this helps :D