question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tag v1.0.2 cannot create an extrinsic using the Utility.batch call using polkadot v.0.9.11

See original GitHub issue

The following code works when connecting to polkadot 0.9.10 but not 0.9.11

Fails when trying compose the batch call

from substrateinterface import SubstrateInterface, Keypair
from substrateinterface.exceptions import SubstrateRequestException

try:
    substrate = SubstrateInterface(
        url="ws://127.0.0.1:9944",
        type_registry_preset='development'
    )
except ConnectionRefusedError:
    print("⚠️ No local Substrate node running, try running 'start_local_substrate_node.sh' first")
    exit()

keypair = Keypair.create_from_uri('//Alice')

call_1 = {
    'call_module': 'Balances',
    'call_function': 'transfer',
    'call_args': {
        'dest':  '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
        'value': 1 * 10**15
    }
}

call_2 = {
    'call_module': 'Balances',
    'call_function': 'transfer',
    'call_args': {
        'dest':  '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
        'value': 1 * 10**15
    }
}

batch_call = substrate.compose_call(
    call_module='Utility',
    call_function='batch',
    call_params={
        'calls': [call_1, call_2]
    }
)

batched_extrinsic = substrate.create_signed_extrinsic(
    call=batch_call,
    keypair=keypair,
    era={'period': 64}
)


try:
    receipt = substrate.submit_extrinsic(batched_extrinsic, wait_for_inclusion=True)

    print('Extrinsic "{}" included in block "{}"'.format(
        receipt.extrinsic_hash, receipt.block_hash
    ))

    if receipt.is_success:

        print('✅ Success, triggered events:')
        for event in receipt.triggered_events:
            print(f'* {event.value}')

    else:
        print('⚠️ Extrinsic Failed: ', receipt.error_message)


except SubstrateRequestException as e:
    print("Failed to send: {}".format(e))

Stacktrace is :

Traceback (most recent call last):
  File "thing2.py", line 36, in <module>
    batch_call = substrate.compose_call(
  File "...pyenvs/core2/lib/python3.8/site-packages/substrateinterface/base.py", line 1422, in compose_call
    call.encode({
  File "...pyenvs/core2/lib/python3.8/site-packages/scalecodec/base.py", line 698, in encode
    self.data = self.process_encode(self.value_serialized)
  File "...pyenvs/core2/lib/python3.8/site-packages/scalecodec/types.py", line 1428, in process_encode
    data += arg_obj.encode(param_value)
  File "...pyenvs/core2/lib/python3.8/site-packages/scalecodec/base.py", line 698, in encode
    self.data = self.process_encode(self.value_serialized)
  File "...pyenvs/core2/lib/python3.8/site-packages/scalecodec/types.py", line 846, in process_encode
    data += element_obj.encode(element)
  File "...pyenvs/core2/lib/python3.8/site-packages/scalecodec/base.py", line 698, in encode
    self.data = self.process_encode(self.value_serialized)
  File "...pyenvs/core2/lib/python3.8/site-packages/scalecodec/types.py", line 1055, in process_encode
    raise ValueError("Value for enum with type_mapping can only have one value")
ValueError: Value for enum with type_mapping can only have one value

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BulatSaifcommented, Sep 30, 2022

Wow, that was fast! Thank you @arjanz, all works. This issue can be closed

1reaction
arjanzcommented, Sep 30, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found