Skip to content

Instantly share code, notes, and snippets.

@arjanz
Created January 20, 2020 08:45
Show Gist options
  • Save arjanz/f4cf77e9e68614dac38de75269a27842 to your computer and use it in GitHub Desktop.
Save arjanz/f4cf77e9e68614dac38de75269a27842 to your computer and use it in GitHub Desktop.
# Install package with: pip install git+https://github.com/polkascan/py-substrate-interface.git@master#egg=substrateinterface
from scalecodec.base import RuntimeConfiguration
from scalecodec.type_registry import load_type_registry_preset
from substrateinterface import SubstrateInterface
from substrateinterface.utils.ss58 import ss58_encode
RuntimeConfiguration().update_type_registry(load_type_registry_preset("default"))
RuntimeConfiguration().update_type_registry(load_type_registry_preset("kusama"))
substrate = SubstrateInterface(url="http://127.0.0.1:9933/")
# Set block_hash to None for chaintip
block_hash = "0x588930468212316d8a75ede0bec0bc949451c164e2cea07ccfc425f497b077b7"
metadata = substrate.get_block_metadata(block_hash=block_hash)
result = substrate.get_chain_block(
block_hash=block_hash,
metadata_decoder=metadata
)
for extrinsic in result['block']['extrinsics']:
if 'account_id' in extrinsic:
signed_by_address = ss58_encode(address=extrinsic['account_id'], address_type=2)
else:
signed_by_address = None
print('\nModule: {}\nCall: {}\nSigned by: {}'.format(
extrinsic['call_module'],
extrinsic['call_function'],
signed_by_address
))
for param in extrinsic['params']:
if param['type'] == 'Address':
param['value'] = ss58_encode(address=param['value'].replace('0x', ''), address_type=2)
print("Param '{}': {}".format(param['name'], param['value']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment