2

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.

Jdawg287
  • 117
  • 5

2 Answers2

4

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:

Arjan
  • 301
  • 1
  • 4
1

OK after digging out a bit more found out that the issue was related to the encoding in parity-scale codec and you need to adjust the network configuration according to your runtime. So I changed from:

    def create_substrate_instance(self, wsport):
        return SubstrateInterface(
                    url=self.rpc_url + wsport,
                    ss58_format=42,
                    type_registry_preset='kusama',
                )

to:

    def create_substrate_instance(self, wsport):
        return SubstrateInterface(
                    url=self.rpc_url + wsport,
                    ss58_format=42,
                    type_registry_preset='substrate-node-template',
                )

and it worked.

Jdawg287
  • 117
  • 5