Created
March 10, 2021 11:40
-
-
Save dmitry-vsl/317f9f17931a9501c98ab0d15893f6c7 to your computer and use it in GitHub Desktop.
Perform Polkadot setKeys tx from python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, json | |
from substrateinterface import SubstrateInterface, Keypair | |
from scalecodec.base import ScaleDecoder, RuntimeConfiguration, ScaleBytes | |
from scalecodec.type_registry import load_type_registry_preset | |
import requests | |
URL = 'wss://fullnode-relay.chachacha.centrifuge.io' | |
keysencoded = '...your keys from rotate keys here...' | |
# Decode session keys | |
RuntimeConfiguration().update_type_registry(load_type_registry_preset("default")) | |
RuntimeConfiguration().update_type_registry(load_type_registry_preset("polkadot")) | |
obj = ScaleDecoder.get_decoder_class('Keys', ScaleBytes(keysencoded)) | |
obj.decode() | |
sessionkeys = obj.value | |
print('Session keys: ' + str(sessionkeys)) | |
# Submit session keys as validator | |
with open('./validator_secret') as file: | |
validator_secret = file.read().strip() | |
keypair = Keypair.create_from_mnemonic(validator_secret) | |
substrate = SubstrateInterface( | |
url=URL, | |
ss58_format=42, | |
type_registry_preset='rococo', | |
) | |
call = substrate.compose_call( | |
call_module='Session', | |
call_function='set_keys', | |
call_params=dict( | |
keys=sessionkeys, | |
proof='' | |
) | |
) | |
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair) | |
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True) | |
print('extrinsic_hash', receipt.extrinsic_hash, 'block_hash', receipt.block_hash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment