0

I apologize if this topic has already been covered. I would like create my cryptocurrency on the Binance Smart Chain (BSC). For this I use the BEP20Token template which is on Github. Everything works perfectly fine except for one point.

I wish users could be able to pay via BNB, BUSD or USDT. I wish users could be able to pay via BSC Tokens too : CAKE, CHESS, FARM, BNB, BAKE, RAMP, BIFI, etc.. I want to make this possible because I don't want to create a closed ecosystem by imposing a single payment method.

Can you send me some smart contract example?

function buyThisThing(address _to, uint256 _quantity) external payable {

    msg.value // <-- it's BNB only ... how accept BUSD or USDT?
    
}

Best Regards

0

1 Answer 1

0

use the ERC20 standard interface "transferFrom" to transfer user token to your contract address.

function buy(address token, address to, uint256 amount) {
 if(token == address(0)) {
   to.call{value : amount}();
 }else {
   ERC20(token).transferFrom(msg.sender, to, amount);
 }
}

and of cause you also need the user to approve your contract to spend their balance before the transfer.

1
  • thank you so much. I will check.
    – seikida
    Mar 24, 2022 at 1:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.