Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwapExactTokensForETH On Pancakeswap #12

Open
mahanamiri opened this issue Apr 27, 2023 · 0 comments
Open

SwapExactTokensForETH On Pancakeswap #12

mahanamiri opened this issue Apr 27, 2023 · 0 comments

Comments

@mahanamiri
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant