Beispiel #1
0
def start_web3connection(RPCaddress=None, account=None):
    """
    get a web3 object, and make it global 
    """
    global w3
    if RPCaddress:
        # HTTP provider
        # (TODO: also try whether IPC provider is faster, when quorum-outside-vagrant starts working)
        w3 = Web3(HTTPProvider(RPCaddress, request_kwargs={'timeout': 120}))
    else:
        # w3 = Web3(Web3.EthereumTesterProvider()) # does NOT work!
        w3 = Web3(Web3.TestRPCProvider())

    print("web3 connection established, blockNumber =",
          w3.eth.blockNumber,
          end=", ")
    #print ("node version string = ", w3.version.node)
    print("node version string = ", w3.clientVersion)
    accountname = "chosen"
    if not account:
        w3.eth.defaultAccount = w3.eth.accounts[
            0]  # set first account as sender
        accountname = "first"
    print(accountname + " account of node is", w3.eth.defaultAccount, end=", ")
    print("balance is %s Ether" %
          w3.fromWei(w3.eth.getBalance(w3.eth.defaultAccount), "ether"))

    return w3
Beispiel #2
0
def get_eth_provider(provider_name):
    # open a connection to a local ethereum node (ganache geth or simple in memory blockchain)
    if provider_name == "in_memory_test_rpc":
        return Web3.TestRPCProvider()

    eth_providers = {
        'local': HTTPProvider('http://localhost:9545'),
        'rinkeby': Web3.IPCProvider(settings.RINKEBY_SOCKET_FILE_PATH),
    }

    return eth_providers[provider_name]