Ethereum: Converting a String to an Indexed List in Python
As you mentioned, using the requests library is not sufficient for this task. You’ll need to manually parse the JSON response from the Ethereum API. Here’s an article that walks through how to achieve this:
Prerequisites
Before we begin, make sure you have the following installed:
ethers.py library (available on PyPI)Install the Required Library
If you don’t already have ethers.py, install it using pip:
pip install ethers.py
Converting a String to an Indexed List

Here’s a step-by-step guide on how to convert a string representing a hexadecimal value to an indexed list (e.g., a list of integers) in Python:
YOUR_API_KEY with your actual key:import requests
api_key = "YOUR_API_KEY"
api_url = f"
requests library to send a GET request to the Ethereum API:import requests
url = api_url
response = requests.get(url)
json() method:data = json.loads(response.text)
transaction_count = data['result'][0]['number']
"0x...") to an integer, and then to a list of integers using the map() function:indexed_list = [int(hex_value) for hex_value in data['result'][0]['hex']]
Putting it all together
Here’s the complete code:
import requests
import json
api_key = "YOUR_API_KEY"
url = f"
response = requests.get(url)
data = json.loads(response.text)
transaction_count = data['result'][0]['number']
indexed_list = [int(hex_value) for hex_value in data['result'][0]['hex']]
print(indexed_list)
Example Use Case
Suppose you have the following hexadecimal string representing an Ethereum address:
0x1234567890abcdef
You can use this string to convert it to an indexed list like so:
indexed_list = [int("0x" + hex_value) for hex_value in data['result'][0]['hex']]
print(indexed_list)
Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
In this example, the hexadecimal string is converted to an integer 0, and then to a list of integers representing the index values.