Skip to content

can't make a trade #128

Closed
Closed

Description

@LucaZanatta

I wrote the following code for trying to make a trade

from uniswap import Uniswap
from web3 import Web3

wallet_address = "xxx"
private_key = "yyyy"
address = Web3.toChecksumAddress(wallet_address)
version = 2  

bsc = "https://bsc-dataseed.binance.org/"
web3 = Web3(Web3.HTTPProvider(bsc))
print(web3.isConnected())
uniswap = Uniswap(address=address, private_key=private_key, version=version, web3=web3)

wbnb = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
token = "0xa872960bc3393b2a19aa1e784ab7f385d543ce37"

wbnb_w = Web3.toChecksumAddress(wbnb)
token_w = Web3.toChecksumAddress(token)

qty = int(.05 * 10**18)

uniswap.make_trade(wbnb_w, token_w, qty)

but I got this output:

Approving 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c...
`---------------------------------------------------------------------------
Error Traceback (most recent call last)
in
----> 1 uniswap.make_trade(wbnb_w, token_w, qty)

~/virtualenv/generale/lib/python3.8/site-packages/uniswap/decorators.py in approved(self, *args, **kwargs)
27 # logger.warning(f"Approved? {token}: {is_approved}")
28 if not is_approved:
---> 29 self._approve(token)
30 if token_two:
31 is_approved = self._is_approved(token_two)

~/virtualenv/generale/lib/python3.8/site-packages/uniswap/uniswap.py in _approve(self, token, max_approval)
850 )
851 logger.warning(f"Approving {_addr_to_str(token)}...")
--> 852 tx = self._build_and_send_tx(function)
853 self.w3.eth.waitForTransactionReceipt(tx, timeout=6000)
854

~/virtualenv/generale/lib/python3.8/site-packages/uniswap/uniswap.py in _build_and_send_tx(self, function, tx_params)
885 tx_params = self._get_tx_params()
886 transaction = function.buildTransaction(tx_params)
--> 887 signed_txn = self.w3.eth.account.sign_transaction(
888 transaction, private_key=self.private_key
889 )

~/virtualenv/generale/lib/python3.8/site-packages/eth_utils/decorators.py in _wrapper(*args, **kwargs)
16 def _wrapper(*args: Any, **kwargs: Any) -> Any:
17 if obj is not None:
---> 18 return self.method(obj, *args, **kwargs)
19 else:
20 return self.method(objtype, *args, **kwargs)

~/virtualenv/generale/lib/python3.8/site-packages/eth_account/account.py in sign_transaction(self, transaction_dict, private_key)
645 raise TypeError("transaction_dict must be dict-like, got %r" % transaction_dict)
646
--> 647 account = self.from_key(private_key)
648
649 # allow from field, only if it matches the private key

~/virtualenv/generale/lib/python3.8/site-packages/eth_utils/decorators.py in _wrapper(*args, **kwargs)
16 def _wrapper(*args: Any, **kwargs: Any) -> Any:
17 if obj is not None:
---> 18 return self.method(obj, *args, **kwargs)
19 else:
20 return self.method(objtype, *args, **kwargs)

~/virtualenv/generale/lib/python3.8/site-packages/eth_account/account.py in from_key(self, private_key)
244 # but without the private key argument
245 """
--> 246 key = self._parsePrivateKey(private_key)
247 return LocalAccount(key, self)
248

~/virtualenv/generale/lib/python3.8/site-packages/eth_utils/decorators.py in _wrapper(*args, **kwargs)
16 def _wrapper(*args: Any, **kwargs: Any) -> Any:
17 if obj is not None:
---> 18 return self.method(obj, *args, **kwargs)
19 else:
20 return self.method(objtype, *args, **kwargs)

~/virtualenv/generale/lib/python3.8/site-packages/eth_account/account.py in _parsePrivateKey(self, key)
692
693 try:
--> 694 return self._keys.PrivateKey(HexBytes(key))
695 except ValidationError as original_exception:
696 raise ValueError(

~/virtualenv/generale/lib/python3.8/site-packages/hexbytes/main.py in new(cls, val)
21 """
22 def new(cls: Type[bytes], val: Union[bool, bytearray, bytes, int, str]) -> "HexBytes":
---> 23 bytesval = to_bytes(val)
24 return cast(HexBytes, super().new(cls, bytesval)) # type: ignore # python/typeshed#2630 # noqa: E501
25

~/virtualenv/generale/lib/python3.8/site-packages/hexbytes/_utils.py in to_bytes(val)
15 return val
16 elif isinstance(val, str):
---> 17 return hexstr_to_bytes(val)
18 elif isinstance(val, bytearray):
19 return bytes(val)

~/virtualenv/generale/lib/python3.8/site-packages/hexbytes/_utils.py in hexstr_to_bytes(hexstr)
48 raise ValueError(f"hex string {padded_hex} may only contain [0-9a-fA-F] characters")
49 else:
---> 50 return binascii.unhexlify(ascii_hex)

Error: Non-hexadecimal digit found`

I was trying to use pancakeswap (wbrb should have 18 decimals).

Activity

  1. liquid-8 commented on Jul 2, 2021

    @liquid-8
    Member

    Private key should be smth like 0x1234567890AbcDeF..............................................
    I'm quite sure private_key contains something completely different
    https://ethereum.stackexchange.com/questions/19257/what-is-the-private-key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions