Skip to content

Swap BNB to BEP20 token #2090

Discussion options

You must be logged in to vote
  let tokenSrc = await routerContract.WETH();       // This corresponds to BNB on the Binance smart chain
    let tokenDest = "0x78867BbEeF44f2326bF8DDd1941a4439382EF2A7"; // address on the testnet
    let tokenPair = [tokenSrc, tokenDest];

    // we pay 0.01 BNB
    const tokenAmountIn = ethers.utils.parseUnits('0.001', 'ether');
    let amounts = await routerContract.getAmountsOut(tokenAmountIn, tokenPair);
    const slippage = 10; // 10%
    const tokenAmountOutMin = amounts[1].sub(amounts[1].mul(slippage).div(100));

    let gasPrice = ethers.utils.parseUnits(`6`, 'gwei');

    const swapTx = await routerContract.swapExactETHForTokens(
            tokenAmountOutMin,
            token…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@ghost
Comment options

@aurbroszniowski
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by aurbroszniowski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants