-
-
Save Hebilicious/3e3da80c2e83d2f6d0d46fd7ef5fd9c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment