polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
239 stars 111 forks source link

ValueError: Value should be 32 bytes long #343

Open ltfschoen opened 1 year ago

ltfschoen commented 1 year ago

i'm using the following dependencies

python-dotenv==1.0.0
substrate-interface==1.7.0

if i try this example https://polkascan.github.io/py-substrate-interface/usage/keypair-creation-and-signing/?h=signature_payload#offline-signing-of-extrinsics

i run a node using substrate-contracts-node 0.25.0-a2b09462c7c

import os
from dotenv import load_dotenv
from substrateinterface import SubstrateInterface, Keypair, KeypairType, ContractCode, ContractInstance

load_dotenv()

provider = "ws://127.0.0.1:9944"

substrate = SubstrateInterface(
    url=provider,
    ss58_format=42,
    type_registry_preset='substrate-node-template',
)

# default development mnemonic
keypair_alice = Keypair.create_from_uri(
    "//Alice",
    crypto_type=KeypairType.SR25519
)
print(keypair_alice.ss58_address)

keypair_bob = Keypair.create_from_uri(
    "//Bob",
    crypto_type=KeypairType.SR25519
)
print(keypair_bob.ss58_address)

call = substrate.compose_call(
    call_module='Balances',
    call_function='transfer',
    call_params={
        'dest': keypair_bob.ss58_address,
        'value': 2 * 10**8
    }
)
era = {'period': 64, 'current': 22719}
nonce = 0
signature_payload = substrate.generate_signature_payload(call=call, era=era, nonce=nonce)

i get the following error:

Traceback (most recent call last):
  File "/app/dapps/ink-python/example/./src/app.py", line 142, in <module>
    signature_payload = substrate.generate_signature_payload(call=call, era=era, nonce=nonce)
  File "/usr/local/lib/python3.9/dist-packages/substrateinterface/base.py", line 1511, in generate_signature_payload
    signature_payload.encode(payload_dict)
  File "/usr/local/lib/python3.9/dist-packages/scalecodec/base.py", line 925, in encode
    self.data = self.process_encode(self.value_serialized)
  File "/usr/local/lib/python3.9/dist-packages/scalecodec/types.py", line 603, in process_encode
    data += element_obj.encode(value[key])
  File "/usr/local/lib/python3.9/dist-packages/scalecodec/base.py", line 925, in encode
    self.data = self.process_encode(self.value_serialized)
  File "/usr/local/lib/python3.9/dist-packages/scalecodec/types.py", line 672, in process_encode
    data += element_obj.encode(value[idx])
  File "/usr/local/lib/python3.9/dist-packages/scalecodec/base.py", line 925, in encode
    self.data = self.process_encode(self.value_serialized)
  File "/usr/local/lib/python3.9/dist-packages/scalecodec/types.py", line 1954, in process_encode
    raise ValueError('Value should be {} bytes long'.format(self.element_count))
ValueError: Value should be 32 bytes long

it is caused because i'm using keypair_bob.ss58_address why doesn't it let me use the value of keypair_bob.ss58_address? note: i get the same error even if i change it to '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', which is the value used in the example in the docs in the link mentioned above