Nethereum.Uniswap-V2-and-V3
Nethereum.Uniswap-V2-and-V3 copied to clipboard
SwapExactTokensForETH On Pancakeswap
Hello, I implemented the following code:
var privatekey = "...";
Account account = new Account(privatekey);
var web3 = new Web3(account, "https://bsc-dataseed1.binance.org:443");
var routerV2Address = "0x10ED43C718714eb63d5aA57B78B54704E256024E";
var uniswapV2Router02Service = new UniswapV2Router02Service(web3, routerV2Address);
var bnb = "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c";
var pa = "0x7F11290E06bfeda487A8ce23d86cFD7E8f5e66c8";
var path = new List<string> { pa, bnb };
BigInteger amountSCN = 100000000000;
var serviceSCN = new Nethereum.StandardTokenEIP20.StandardTokenService(web3, pa);
var deadline = DateTimeOffset.Now.AddMinutes(85).ToUnixTimeSeconds();
var swapTokensForExactTokens = new Nethereum.Uniswap.Contracts.UniswapV2Router02.ContractDefinition.SwapExactTokensForETHFunction
{
AmountOutMin = Web3.Convert.ToWei(0),
Path = path,
Deadline = deadline,
To = account.Address,
AmountIn = amountSCN,
GasPrice = Web3.Convert.ToWei(20, UnitConversion.EthUnit.Gwei),
Gas = 100000
};
var approveReceipt = await serviceSCN.ApproveRequestAndWaitForReceiptAsync("0x10ED43C718714eb63d5aA57B78B54704E256024E", 109828292673427);
var swapReceipt = await uniswapV2Router02Service.SwapExactTokensForETHRequestAndWaitForReceiptAsync(swapTokensForExactTokens);
But my problems are not solved by the following method:
var approveReceipt = await serviceSCN.ApproveRequestAndWaitForReceiptAsync("0x10ED43C718714eb63d5aA57B78B54704E256024E", 109828292673427);
I manually called this method via smart contract: https://bscscan.com/tx/0x8d985fbbea13e895bb20e00a5607520da4137d026445a6d882dfe4224c365568
And after that I called the next step of the code:
var swapReceipt = await uniswapV2Router02Service.SwapExactTokensForETHRequestAndWaitForReceiptAsync(swapTokensForExactTokens);
Unfortunately, I tried many times and failed every time.
https://bscscan.com/tx/0xaf43bd21b1263c43e4afeb041ee8d9d0a256318396dced6a43fe3c43448176d8