Skip to content

Uniswap: KeyError: 'binance' #126

Closed
Closed

Description

@Theagainmen

Hello there,

I just installed the latest version of Uniswap Python and it fails here:

from uniswap import Uniswap
from web3 import Web3

address = None                      # or None if you're not going to make transactions
private_key = None                # or None if you're not going to make transactions
version = 2                             # specify which version of Uniswap to use

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)

The web3 connection return true but I keep getting this error:

Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/XX/XX/UniSwap_API_test.py", line 24, in <module>
    uniswap = Uniswap(address=address, private_key=private_key, version=version, web3=web3)
  File "C:\Users\User\PycharmProjects\XX\venv\lib\site-packages\uniswap\uniswap.py", line 121, in __init__
    router_contract_addr = _router_contract_addresses_v2[self.network]
KeyError: 'binance'

Could anyone help me out?

Activity

  1. liquid-8 commented on Jun 28, 2021

    @liquid-8
    Member

    That's a bug definitely.
    You need to add BSC factory/router contracts addresses here

    _factory_contract_addresses_v2 = {

    _factory_contract_addresses_v2 and _router_contract_addresses_v2 accordingly

    I suppose you gonna use pancakeswap v2 so addresses are
    0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73 for factoryV2
    0x10ED43C718714eb63d5aA57B78B54704E256024E for routerV2

  2. LucaZanatta commented on Jun 29, 2021

    @LucaZanatta

    I added the 2 lines in the dictionary, but I still have the same error.

    This is the dictionary. Is it true?

    _factory_contract_addresses_v2 = {
        "mainnet": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
        "ropsten": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
        "rinkeby": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
        "görli": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
        "xdai": "0xA818b4F111Ccac7AA31D0BCc0806d64F2E0737D7",
        "factoryV2": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
        "routerV2": "0x10ED43C718714eb63d5aA57B78B54704E256024E", 
    }
    
  3. liquid-8 commented on Jun 30, 2021

    @liquid-8
    Member

    No, it should be

    _factory_contract_addresses_v2 = {
    ....
    "binance": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
    }
    

    and next dictionary

    _router_contract_addresses_v2 = {
    ....
    "binance": "0x10ED43C718714eb63d5aA57B78B54704E256024E",
    }
    
  4. ErikBjare commented on Jul 2, 2021

    @ErikBjare
    Member

    Fixed in #129

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