pyetherscan.response module

A module used to define API-specific response objects. All Etherscan API requests return an instance of EtherscanResponse, extended to meet the endpoint’s specific needs.

See /response for an overview.

class pyetherscan.response.BlockRewardsResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

Represents a response object for a block / uncle rewards API call to the Etherscan Blocks endpoint.

Available attributes:
  • rewards_data: A dict of the rewards for the block and any uncles mined.

Example:

parse_response()[source]

Parses a token account balance request response. Example API response output:

{
    "status": "1",
    "message": "OK",
    "result": {
        "blockNumber": "2165403",
        "timeStamp": "1472533979",
        "blockMiner": "0x13a06d3dfe21e0db5c016c03ea7d2509f7f8d1e3",
        "blockReward": "5314181600000000000",
        "uncles": [
            {
                "miner": "0xbcdfc35b86bedf72f0cda046a3c16829a2ef41d1",
                "unclePosition": "0",
                "blockreward": "3750000000000000000"
            }, {
                "miner": "0x0d0c9855c722ff0c78f21e43aa275a5b8ea60dce",
                "unclePosition": "1",
                "blockreward": "3750000000000000000"
            }
        ],
        "uncleInclusionReward": "312500000000000000"
    }
}
class pyetherscan.response.BlocksMinedByAddressResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

parse_response()[source]

Parses a blocks mined by address request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":[
        {
            "blockNumber":"3462296",
            "timeStamp":"1491118514",
            "blockReward":"5194770940000000000"
        }, {
            ...
        }
    ]
}
class pyetherscan.response.ContractABIByAddressResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

parse_response()[source]

Parses a contract abi by address request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":[
        {
            'constant': True,
            'inputs': [
                {
                    'name': '',
                    'type': 'uint256'
                }
            ],
            'name': 'proposals',
            'outputs': [
                {'name': 'recipient', 'type': 'address'},
                {'name': 'amount', 'type': 'uint256'},
                {'name': 'description', 'type': 'string'},
                {'name': 'votingDeadline', 'type': 'uint256'},
                {'name': 'open', 'type': 'bool'},
                {'name': 'proposalPassed', 'type': 'bool'},
                {'name': 'proposalHash', 'type': 'bytes32'},
                {'name': 'proposalDeposit', 'type': 'uint256'},
                {'name': 'newCurator', 'type': 'bool'},
                {'name': 'yea', 'type': 'uint256'},
                {'name': 'nay', 'type': 'uint256'},
                {'name': 'creator', 'type': 'address'}
            ],
            'type': 'function'
        }, {
            ...
        }
    ]
}
class pyetherscan.response.ContractStatusResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

Represents a response object for a contract status call within the Etherscan Contracts endpoint.

Available attributes:
  • contract_status: The status of the contract returned as a json object.

Example:

parse_response()[source]

Parses a transaction status by hash request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":{
        "isError":"1",
        "errDescription":"Bad jump destination"
    }
}
class pyetherscan.response.EtherscanResponse(resp)[source]

Bases: object

This is the parent class for all Etherscan API responses.

All child classes must define parse_response()

Upon initialization, the class sets the following attributes:
  • etherscan_response: The response json from Etherscan.
  • response_object: The requests.Response returned by the API call.
  • status: The Etherscan response status (independent of the requests.Response status).
  • message: The Etherscan response message.
  • Class-specific attributes are then set via the call to parse_response().

If a 403 error is received it will raise an EtherscanRequestError. This typically means the rate limit has been reached. By default, get_request() and post_request() will handle this and automatically retry the request.

parse_response()[source]

The method that will parse the response object and store all attributes within the specific API response object.

class pyetherscan.response.MultiAddressBalanceResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

Represents a response object for a multi address account balance call within the Etherscan Accounts endpoint.

Available attributes:
  • balances: The balances of the addresses returned as a dict.

Example:

parse_response()[source]

Parses a multi balance request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":[
        {
            "account":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
            "balance":"40807168564070000000000"
        }, {
            "account":"0x63a9975ba31b0b9626b34300f7f627147df1f526",
            "balance":"332567136222827062478"
        }, {
            "account":"0x198ef1ec325a96cc354c7266a038be8b5c558f67",
            "balance":"12005264493462223951724"
        }
    ]
}
class pyetherscan.response.SingleAddressBalanceResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

Represents a response object for a single address account balance call within the Etherscan Accounts endpoint.

Available attributes:
  • balance: The balance of the address returned as a float.

Example:

parse_response()[source]

Parses a single balance request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":"40807168564070000000000"
}
class pyetherscan.response.TokenAccountBalanceResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

Represents a response object for a token account balance call within the Etherscan Tokens endpoint.

Available attributes:
  • balance: The account balance of a token (by contract address)

returned as a float.

Example:

parse_response()[source]

Parses a token account balance request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":"135499"
}
class pyetherscan.response.TokenSupplyResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

Represents a response object for a token supply call within the Etherscan Tokens endpoint.

Available attributes:
  • total_supply: The total supply of the token returned as a float.

Example:

parse_response()[source]

Parses a token supply by address request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":"21265524714464"
}
class pyetherscan.response.TransactionsByAddressResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

parse_response()[source]

Parses a transactions by address request response. Example API response output:

{
    "status":"1",
    "message":"OK",
    "result":[
        {
            "blockNumber":"54092",
            "timeStamp":"1439048640",
            "hash":"0x9c81f44c29ff0226f83...",
            "nonce":"0",
            "blockHash":"0xd3cabad6adab0b5...",
            "transactionIndex":"0",
            "from":"0x5abfec25f74cd88437631a7731906932776356f9",
            "to":"",
            "value":"11901464239480000000000000",
            "gas":"2000000",
            "gasPrice":"10000000000000",
            "isError":"0",
            "input":"0x6060b91f525b5ae7a03d...",
            "contractAddress":"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
            "cumulativeGasUsed":"1436963",
            "gasUsed":"1436963",
            "confirmations":"3921024"
        }, {
            ...
        }
    ]
}
class pyetherscan.response.TransactionsByHashResponse(resp)[source]

Bases: pyetherscan.response.EtherscanResponse

parse_response()[source]

Parses a transactions by hash request response. Example API response output:


{

“status”:”1”, “message”:”OK”, “result”:[

{
“blockNumber”:”1743059”, “timeStamp”:”1466489498”, “from”:”0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2”, “to”:”0x66a1c3eaf0f1ffc28d209c0763ed0ca614f3b002”, “value”:”7106740000000000”, “contractAddress”:””, “input”:””, “type”:”call”, “gas”:”2300”, “gasUsed”:”0”, “isError”:”0”, “errCode”:”“

}

]

}