Search code examples
pythonblockchainsubstratepolkadot

Why can't I send an extrinsic from py-substrate-interface?


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.


Solution

  • 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: