0

i have a token that reward eth to token holders but i want to use another coin( doge/cardano) for reward. i am not able to do it. any help would be great.

here is the code

    function swapTokensForEth(uint256 tokenAmount) private {
    // generate the uniswap pair path of token -> weth
    address[] memory path = new address[](2);
    path[0] = address(this);
    path[1] = uniswapV2Router.WETH();

    _approve(address(this), address(uniswapV2Router), tokenAmount);

    // make the swap
    uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
        tokenAmount,
        0, // accept any amount of ETH
        path,
        address(this),
        block.timestamp
    );
}

function swapAndSendDividends(uint256 tokens) private {
    swapTokensForEth(tokens);
    uint256 dividends = address(this).balance;

    (bool success,) = address(dividendTracker).call{value: dividends}("");
    if (success) {
        emit SentDividends(tokens, dividends);
    }
}

}

full code in git hub: https://github.com/coderbang1/eth-distri-token/blob/main/code

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Sep 1, 2021 at 11:27

1 Answer 1

0

Do like this and notice the path[2]

 // generate the pancakeswap pair path of weth -> dividend
    address[] memory path = new address[](3);
    path[0] = address(this);
    path[1] = pancakeswapV2Router.WETH();
    path[2] = _dividendRewardToken;

    _approve(address(this), address(pancakeswapV2Router), tokenAmount);

    // make the swap
    pancakeswapV2Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
      tokenAmount,
      0, // accept any amount of tokens
      path,
      recipient,
      block.timestamp
    );
5
  • notice path 2 ?
    – stofu
    Aug 31, 2021 at 16:49
  • Here dividendRewardToken is the contract address of the token you want to give reward for your holders path[2] = _dividendRewardToken;
    – safi
    Sep 1, 2021 at 13:47
  • but it gives me error when i add it
    – stofu
    Sep 1, 2021 at 14:22
  • What error are you getting?
    – safi
    Sep 2, 2021 at 14:04
  • not identifies declared
    – stofu
    Sep 2, 2021 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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