how to buy/sell bsc tokens on pancakeswap from a solidity smart contract? - solidity

I just start to learn solidity and I've finished a couple courses and I want some help to create my first working smart contract.
The smart contract I want to build will buy and sell tokens on the pancakeswap platform from a smart contract; it like my smart contract will start interacting with a pancakeswap contract to execute some trades, doing the same stuff as I'm using their website.
Any help will be appreciated
I have tried to add the interfaces I need to start the interaction between my contract and pancakeswap router contract to use the function

Related

How to deposit $CAKE in a pool on pancakeswap through solidity smart contract?

I am developing a smart contract on solidity where user can deposit $CAKE in my pool and after depositing, the deposited $CAKE will be automatically redirected to some other pool. But I don't know how to write this! Can anyone help?
I don't have any clue on how to do this or even if it is possible?

OpenSea Lazy Minting with Custom Contract

How can I get OpenSea to lazy mint with a custom contract I built?
In other words, how do I get OpenSea to communicate with my custom contract during the sale of a lazy minted token?
I don’t want the lazy minted token to show up on the OpenSea smart contract. I want it to live on my custom contract after purchase.

How do I modify my smart contract code so I'm the only one who can sell tokens? Everyone else send their tokens to me to exchange for either ETH, etc

So I have a token that has about 103 users. What I need to do is restrict the ability to sell those tokens to just myself the developer, so the other users can redeem their tokens for ETH or MATIC by sending to me. The alternative would be to just write a new smart contract, including this function and moving all users to the new platform. How would I write that new contract?
The first, you can't change code of deployed contract in Ethereum.
The second, look at ERC-20 and ERC-721 (NFT) standarts, its already have functionality you need.

how to withdraw all tokens from the my contract in solidity after deployment?

I am deployed ERC-721 smart contract and sale was started and 3ETH in my contract
Now I am worried about how can I withdraw ETH from the contract to my wallet. How can I upgrade my contract with the withdrawal function?
Please help
Thanking in anticipation
If the contract is already deployed with no withdraw function, no proxie, without a delegatecall, is very hard or imposible to withdraw the ether

PancakeSwap API / Swaping BNB with Binance Smart Chain's API

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