How to I get something specific out of this block?

Viewed 67

So I have this block of information in one list class. Whenever I do print(block) it loops through the entire list and outputs following:

[{'version': 3, 'from': 'hx7ccc54932b913c71f7051e9dc1b621074c91d462', 'to': 'hxbf2a3504318b6315e38eeb87ee84402361a7d644', 'stepLimit': 1000000, 'timestamp': 1547599428802897, 'nid': 1, 'value': 30000000000000000000000, 'signature': 'ehslHJOj5e6apGhxEbZ6SESx5fagazIPNI5BjCo3sMYAGWVMQbiN8w/PH8BHhHmXBtwEGWiqEuTU5fa4toeOvwE=', 'txHash': '0x833bf64c224209ce850df8f9d47b9b6fcb1471cee93d8c946c2a2bfbded3fb2a'}]

I have tried to do print(block[1]) as well as print(block[0][1]) but it says out of range?

from iconsdk.icon_service import IconService
from iconsdk.providers.http_provider import HTTPProvider

def main():
    icon_service = IconService(HTTPProvider("https://ctz.solidwallet.io/api/v3"))
    block = icon_service.get_block("latest")['confirmed_transaction_list']
    print(block)


if __name__ == '__main__':
    main()

I expect it to give me the result of 'to' (hxbf2a3504318b6315e38eeb87ee84402361a7d644) instead of looping through the entire block even though i never told the program to do so.

1 Answers

Try this, get the key and print it:

from iconsdk.icon_service import IconService
from iconsdk.providers.http_provider import HTTPProvider

def main():
    icon_service = IconService(HTTPProvider("https://ctz.solidwallet.io/api/v3"))
    block = icon_service.get_block("latest")['confirmed_transaction_list']
    print(block[0]['to'])


if __name__ == '__main__':
    main()

Then it will work.

Related