import json


def getEndpoint(chain='mainnet'):
    """
    Extracts the infura endpoint website given the input chain name from among
    the possible values:
        mainnet
        kovan
        rinkeby
        goerli
        ropsten

    Assumes that at a folder level above this python file, there is a json file
    containing the credentials fo an infura account, called secrectInfuraCredentials.json
    
    

    Parameters
    ----------
    chain : str, optional
        DESCRIPTION. The default is 'mainnet' and currently only works for mainnet.

    Raises
    ------
    ValueError
        DESCRIPTION.

    Returns
    -------
    endpoint : str
        url to endpoint for specified chain.

    """
    with open('../secretInfuraCredentials.json','r') as file:
        INFURA_CREDENTIALS = json.load(file)
    try:
        endpoint = INFURA_CREDENTIALS[f'{chain.upper()}_ENDPOINT']
    except:
        raise ValueError(f'COULD NOT FIND ENDPOINT FOR SPECIFIED CHAIN: {chain.upper()}')
    return endpoint