Smart contract that buys BEP20 tokens

Can someone point me in the direction of how to create a smart contract that buys BEP20 tokens? For example, a user inputs 1 BNB and gets three different tokens on BEP20 for this automatically in his wallet.

Thanks in advance

The smart contract has to have those tokens that are available for sale, you make a function to buy tokens, and in that function you transfer those BEP20 tokens to the address that sent that 1 BNB to the smart contract.

Sometimes you can find the contract source on etherscan for various smart contracts, for example this (it doesn’t do what you want, but maybe you can find another smart contract that it is closer to what you are looking for).

Thanks! But I do not even know how to create a function to buy tokens (and buy from where?). I found this:

Here I can swap tokens for ETH on Uniswap. That’s basically what I want, but swapping BEP20 tokens is not possible with this.

then maybe this is what you need:

1 Like

Thanks, that brings me a step further!