所以我将这一信息块放在一个列表类中。每当我执行print(block)时,它就会遍历整个列表并输出以下内容:
[{'version':3,'from': 'hx7ccc54932b913c71f7051e9dc1b621074c91d462','至': 'hxbf2a3504318b6315e38eeb87ee84402361a7d644','stepLimit':1000000, 'timestamp':1547599428802897,'nid':1,'value': 30000000000000000000000,'签名': 'ehslHJOj5e6apGhxEbZ6SESx5fagazIPNI5BjCo3sMYAGWVMQbiN8w / PH8BHhHmXBtwEGWiqEuTU5fa4toeOvwE =', 'txHash': '0x833bf64c224209ce850df8f9d47b9b6fcb1471cee93d8c946c2a2bfbded3fb2a'}]
我尝试做print(block [1])和print(block [0] [1]),但是说超出范围了?
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()
我希望它能给我'to'(hxbf2a3504318b6315e38eeb87ee84402361a7d644)的结果,而不是遍历整个块,即使我从未告诉程序这样做。
答案 0 :(得分:4)
尝试一下,获取密钥并打印:
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()
然后它将起作用。