Skip to content

Instantly share code, notes, and snippets.

@Hebilicious
Last active April 21, 2021 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hebilicious/3e3da80c2e83d2f6d0d46fd7ef5fd9c6 to your computer and use it in GitHub Desktop.
Save Hebilicious/3e3da80c2e83d2f6d0d46fd7ef5fd9c6 to your computer and use it in GitHub Desktop.
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