You need to have the Sudo
pallet deployed, which is often the case in development networks.
Then you can wrap the call in Sudo::sudo
and sign it with the sudo key.
Example of Alice being sudo and stealing funds from Bob via sudo force_transfer;
You can try this code on a substrate --dev
node to see it working.
from substrateinterface import SubstrateInterface, Keypair
from substrateinterface.exceptions import SubstrateRequestException
substrate = SubstrateInterface(
url="ws://127.0.0.1:9944",
)
# Derive the Alice and Bob accounts
alice = Keypair.create_from_uri('//Alice')
bob = Keypair.create_from_uri('//Bob')
# Query the sudo key
sudo_key = substrate.query(
module='Sudo',
storage_function='Key',
)
print("Sudo key: {}".format(sudo_key.value))
if sudo_key.value == alice.ss58_address:
print("Alice is the sudo key")
else:
raise Exception("Unknown or no sudo key")
# Alice steals funds from Bob via sudo force_transfer:
call = substrate.compose_call(
call_module='Balances',
call_function='force_transfer',
call_params={
'source': bob.ss58_address,
'dest': alice.ss58_address,
'value': 100000000000000000000,
}
)
# Wrap it in sudo.
call = substrate.compose_call(
call_module='Sudo',
call_function='sudo',
call_params={
'call': call.value,
}
)
# Signed by Alice
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=alice)
try:
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
print("Extrinsic '{}' sent and included in block '{}'".format(receipt.extrinsic_hash, receipt.block_hash))
except SubstrateRequestException as e:
print("Failed to send: {}".format(e))