This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Selling tokens is not working #1635
Comments
Hey @Tomix3D, it looks like in your logic you are not approving before a swap. You have to approve your |
@zemse I'm sending approve request before swap but I also noticed that in approve tx from pancakeswap v2 is amount set to I'm trying to sell ECOIN tokens (0x4cbdfad03b968bf43449d0908f319ae4a5a33371) so I changed I am just a beginner and I will be grateful for any help.. Thanks. |
Right now after I changed my gasLimit I successfully sold my tokens! Thank you @zemse !!! Is there any way how to specify gasLimit for all tokens? Would it be okay to set it to 1M instead of 210,000? Thanks. |
I see you are trying to sell tokens, the token contract is not verified and it is likely that they have a require statement there which prevents you from selling. (That's what scam tokens do). I want to know who told you to do this bot? Is there any course? Because seems someone is clearly scamming a lot of people who are following that course/tutorial. |
How can I set this infinite approve? It was just random coin for testing buy/sell requests... and it was my idea to create this bot. |
Hello, Can you copy your source code after resolving the issue? |
What kind of gaslimit did you change to? |
I changed gasLimit: parseInt(reqUrl.searchParams.get('gasLimit')).. I was sending 210,000 gas limit and I changed it to 310,000. And also I changed 'ether' in ethers.utils.parseUnits to 18 for WBNB token and 9 to other tokens. |
Clear for the first point. but I don't really understand the second point. What are 18 and 9? |
18 and 9 are decimals of tokens. WBNB has 19 decimals and other tokens are using 9 decimals. |
so that mean you change your gasLimit to ethers.utils.parseUnits('0.01', 18); instead of ethers.utils.parseUnits('0.01', 'ether'); ? |
Please give the code you changes, and where you apply it to the code as well |
Wbnb has 19 decimals? Do you mean 18? |
Yes, I mean 18. Sorry. |
But notice that some of tokens are having also 18 decimals ... so send correct number. |
I saw that it's the number of WBNB which you want to spend. Not related to gasLimit and gasPrice as well |
I send gas with parameters. |
|
I use int format: |
Clear. Thank you |
Can anyone help me out with the await tx.wait(). for some reason, it keeps saying that "this should not happen" in the console. // Approves the transaction and then gives out a receipt check bscscan.com It gets to the point where it says "After Approve" and then stops and pushes out that onto the console. Thanks. |
Hi, what is the url of the provider? And what contract are you trying to sell? I think it could be that Ankr provides perfect urls for the provider. Hope this helps, all the best |
Thanks for the reply Geoff, I am using Ankr as the wss, I was assuming it would take the request better then the https. I was debugging it and it's in the websocket.js file in where it's getting caught. |
Any other reason why it's getting stuck at the tx.wait() I have used the wss and the https API's from Ankr and still getting nothing. The transaction is going through just not buying the token of choice. Thanks. *** Update *** Got it working!! Thanks for all the snippets of code everyone!! Let us all make some money!! Don't be too greedy! Leave some for the rest! Haha |
Alright, I'm stuck again. Here is what's going on. Getting this for the buying of the token and I'm only getting a fraction of the token. Any help would be appreciated. Buying new token |
What method/function are you calling? SwapTokensForTokens()? That one you should not use. I use something like swapEthForTokensWithFeesEnabled().. (not sure if that's the correct function name, but something like that). |
I could send you a working script that buys and sells for you, only for 1 BNB. I can give some guidance 😀 |
If I can't figure this out haha I just might take you up on that. I have tried some others like this "swapExactTokensForETHSupportingFeeOnTransferTokens" with no luck haha. Still trying to figure this out haha |
Lol, what are the params for "swapExactTokensForETHSupportingFeeOnTransferTokens" that you pass? |
By the wat, the token in has only 15 zero's... BNB and WBNB uses 18 decimals, so... |
Haha for real though haha I know a bit of node.js this is something different haha. I am passing these through my function "function swapExactTokensForETHSupportingFeeOnTransferTokens( |
I'm trying to figure that one out haha I have this for the decimals in place. Not really sure how to change that " |
I have changed it to 18 : 9 also with no luck |
const testTx = async () => { That is what i am running |
Appreciate your help also Geoff! |
Well, the steps are as follows:
Have you added "swapExactTokensForETHSupportingFeeOnTransferTokens" to the ABI interface before calling this one? Maybe send the entire script to me by email or pm. I Will debug for you. But don't forget me if you make profit, alright? |
What's your email? An for sure if you can help me out I totally would send you some no doubt brotha! |
I just want to be able to grasp it a little more so I know fully what's going on haha so definitely help me and I'll help you. |
Allright bro 😀, You can send to geoffsmiths1981@gmail.com. Let's help eachother. 🤘 |
This seems like an API issue, not an ethers issue, but it may be useful for future developers, so I'm moving it to the discussions. Thanks! :) |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hey! I'm trying to buy and sell tokens on pancakeswap v2. I'm buying tokens with WBNB and it's working correctly.. but when I try to sell my tokens (so my tokenOut is WBNB) transaction fails.
My code and output..
Sending parameters are:
slippageTolerance => 10
gasPrice => 5
gasLimit => 210000
`
const http = require('http');
const ethers = require('ethers');
http.createServer(function (req, res) {
const baseURL = req.protocol + '://' + req.headers.host + '/';
const reqUrl = new URL(req.url,baseURL);
');
}).listen(3030);`
`
tokenIn: 250296617395320000000000000 0x4cbdfad03b968bf43449d0908f319ae4a5a33371
tokenOut: 761663233022492496404 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c
line 115
(node:1) UnhandledPromiseRejectionWarning: Error: transaction failed (transactionHash="0x78225d5214194dd0683b2cff32e2b57c37a3c4ae39b39f42f49db802be60b190", transaction={"nonce":85,"gasPrice":{"type":"BigNumber","hex":"0x012a05f200"},"gasLimit":{"type":"BigNumber","hex":"0x03d090"},"to":"0x10ED43C718714eb63d5aA57B78B54704E256024E","value":{"type":"BigNumber","hex":"0x00"},"data":"0x38ed1739000000000000000000000000000000000000000000cf0a5ed139d9491f9f80000000000000000000000000000000000000000000000000294a3362f81d3d521400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000082084929560e3c274373e5cdcd9a5dbbf8c3b1cd0000000000000000000000000000000000000000000000000000000060b5017d00000000000000000000000000000000000000000000000000000000000000020000000000000000000000004cbdfad03b968bf43449d0908f319ae4a5a33371000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c","chainId":56,"v":147,"r":"0x2427f352d2299477db485ad812d7d47957643489d127e93eeee9ba35e79367ac","s":"0x47b27ad4973c5c339d4ecac9f19e343f2491d8bb22e2dd3cfaf3b9bd03417bb4","from":"0x82084929560E3C274373e5CdCD9A5DBbf8C3b1cD","hash":"0x78225d5214194dd0683b2cff32e2b57c37a3c4ae39b39f42f49db802be60b190","type":null}, receipt={"to":"0x10ED43C718714eb63d5aA57B78B54704E256024E","from":"0x82084929560E3C274373e5CdCD9A5DBbf8C3b1cD","contractAddress":null,"transactionIndex":144,"gasUsed":{"type":"BigNumber","hex":"0xde07"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x0a138a74834c6802e0dd3b3ecfcef62d5b206a6d6a5bd5d78c26b2e0ad878d55","transactionHash":"0x78225d5214194dd0683b2cff32e2b57c37a3c4ae39b39f42f49db802be60b190","logs":[],"blockNumber":7891530,"confirmations":1,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x015737ed"},"status":0,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.2.0)
at Logger.makeError (/app/node_modules/@ethersproject/logger/lib/index.js:187:21)
at Logger.throwError (/app/node_modules/@ethersproject/logger/lib/index.js:196:20)
at JsonRpcProvider. (/app/node_modules/@ethersproject/providers/lib/base-provider.js:1301:36)
at step (/app/node_modules/@ethersproject/providers/lib/base-provider.js:48:23)
at Object.next (/app/node_modules/@ethersproject/providers/lib/base-provider.js:29:53)
at fulfilled (/app/node_modules/@ethersproject/providers/lib/base-provider.js:20:58)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag '--unhandled-rejections=strict' (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.`
The text was updated successfully, but these errors were encountered: