Hello guys I am working on submitting an extrinsic via the py-substrate-interface, but for some reason I keep getting an error while following the sample mentioned here. My code is as follows:
def send_funds(self, destination, amount):
self.log.info("Sending {} DOT to {} ...".format(amount, destination.strip()))
substrate = self.create_substrate_instance(self.node_ws_port[0])
keypair = Keypair.create_from_mnemonic('level payment mom grape proof display cause engage erupt rain hair arm')
print(keypair)
call = substrate.compose_call(
call_module='Balances',
call_function='transfer',
call_params={
'dest': destination,
'value': ceil(amount * DOT)
}
)
try:
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
except Exception as e:
print(e)
try:
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
self.log.info("Extrinsic '{}' sent and included in block '{}'".format(receipt.extrinsic_hash, receipt.block_hash))
self.log.info("{} DOT sent to address: {}".format(amount, destination))
except SubstrateRequestException as e:
self.log.error("Failed to send: {}".format(e))
I put a try and except block here:
try:
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
except Exception as e:
print(e)
and I get the following error while running this code block:
No more bytes available (offset: 80 / length: 72)
How can I resolve this problem.
Most of the time a RemainingScaleBytesNotEmptyException
is raised, it is type registry related. In a Substrate runtime (like Kusama, Polkadot, etc) specific types are defined, which are not (yet) exposed in the metadata, so libraries have to include a decomposition to primitives of those types.
Some pointers for troubleshooting:
The wrong type registry is being used. Most of the time py-substrate-interface can auto-discover which chain its talking to, so only the url
have to be specified (https://github.com/polkascan/py-substrate-interface#autodiscover-mode). But with custom runtimes or development properties like type_registry_preset
and ss58_format
need to be set manually
Because of a recent runtime upgrade the local type registry is out-dated and needs to be updated. This can be achieved by updating the py-scale-codec
package, run the substrate.reload_type_registry()
function or always use the remote type registries with the use_remote_preset
kwarg (See https://github.com/polkascan/py-substrate-interface#keeping-type-registry-presets-up-to-date)
When developing a custom runtime, introduced types can be added in a custom JSON file in the format like https://github.com/polkascan/py-scale-codec/blob/master/scalecodec/type_registry/rococo.json and provided during init (See https://github.com/polkascan/py-substrate-interface#substrate-node-template)