0

I've created two Bep20 tokens (old/new) and I was wondering if I could write a smart contract that exchanges/swaps old tokens for new ones.

Is there a simple way to exchange two Bep20 tokens using a smart contract?

Any guidance, related links would help a ton. (Hope the question is not too flat).

1
  • 1
    What did you try? The obvious solution of sending the old tokens to the contract, and the contract minting new tokens should work.
    – Ismael
    Jul 13 '21 at 21:58
0

Refer the below code

// swap 1:1 
function swap(uint256 amount) external {
        
        IERC20(tokenA).transferFrom(msg.sender, address(0), amount);  // I am buring the token A by sending it to zero address, you can modify the to address
        IERC20(tokenB).transfer(msg.sender, amount);
        
        emit Swapped(msg.sender, amount);
    }

Hope it helps!

1
  • Thanks! I've found a different solution as well
    – patrick
    Jul 15 '21 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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