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

Incorrect Token Value #1

Open
spmvoss opened this issue Jun 12, 2021 · 5 comments
Open

Incorrect Token Value #1

spmvoss opened this issue Jun 12, 2021 · 5 comments

Comments

@spmvoss
Copy link

spmvoss commented Jun 12, 2021

When you convert the token value from and to wei, you use the built in functions with the parameter 'ether'. However, if the number of decimals of the token that we are selling is different from that of (W)BNB this will give the incorrect value. You want to obtain the decimals from the token contract and then do something like

balance = raw_balance / math.pow(10, decimals)
raw_balance = balance * math.pow(10, decimals)

@jiangdydy
Copy link

Have you ever met the situation that you can sell normally when Decimals is 18, but report an error when Decimals is 9?
Fail with error 'Pancake: K'

@PenkoMlakar
Copy link

I too am able to make a successful sell only when decimals == 18.
If decimals != 18 then trade fails with "Fail with error 'Pancake: K'".
Any idea how to solve that?

@grydev
Copy link

grydev commented Nov 14, 2021

Hey guys,

I still have the same problem. Did you find anything new?
I tried a lot, loosing all my money on fees while testing lol.

I tried to calculate the value with balance = balanceOf * math.pow(10, dec)

@spmvoss @jiangdydy @PenkoMlakar

@astw
Copy link

astw commented Nov 19, 2021

My token is 18 decimals. I got this error message.
Please help me @spmvoss @CodeWithJoe2020

'nonce': nonce

File "C:\Python37-32\lib\site-packages\web3\contract.py", line 1089, in buildTransaction
**self.kwargs
File "C:\Python37-32\lib\site-packages\web3\contract.py", line 1650, in build_transaction_for_function
prepared_transaction = fill_transaction_defaults(web3, prepared_transaction)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
return self.func(*args, **kwargs)
File "C:\Python37-32\lib\site-packages\web3_utils\transactions.py", line 102, in fill_transaction_defaults
default_val = default_getter(web3, transaction)
File "C:\Python37-32\lib\site-packages\web3_utils\transactions.py", line 66, in
'gas': lambda web3, tx: web3.eth.estimate_gas(tx),
File "C:\Python37-32\lib\site-packages\web3\eth.py", line 735, in estimate_gas
return self._estimate_gas(transaction, block_identifier)
File "C:\Python37-32\lib\site-packages\web3\module.py", line 60, in caller
null_result_formatters)
File "C:\Python37-32\lib\site-packages\web3\manager.py", line 190, in request_blocking
null_result_formatters)
File "C:\Python37-32\lib\site-packages\web3\manager.py", line 167, in formatted_response
apply_error_formatters(error_formatters, response)
File "C:\Python37-32\lib\site-packages\web3\manager.py", line 67, in apply_error_formatters
formatted_resp = pipe(response, error_formatters)
File "cytoolz/functoolz.pyx", line 667, in cytoolz.functoolz.pipe
return c_pipe(data, funcs)
File "cytoolz/functoolz.pyx", line 642, in cytoolz.functoolz.c_pipe
data = func(data)
File "C:\Python37-32\lib\site-packages\web3_utils\method_formatters.py", line 569, in raise_solidity_error_on_revert
raise ContractLogicError(response['error']['message'])
web3.exceptions.ContractLogicError: execution reverted: Pancake: K

@henrytirla
Copy link

I too am able to make a successful sell only when decimals == 18. If decimals != 18 then trade fails with "Fail with error 'Pancake: K'". Any idea how to solve that?

Call the decimal of the token you are trying to sell and use that instead of ether
decimals = getTokenName.functions.decimals().call()
DECIMAL = 10 ** decimals
minimum amount sell now can be = 3 * DECIMAL.# you are selling 3 units of your token.
I hope this helps

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

6 participants