Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Value should be 32 bytes long #343

Open
ltfschoen opened this issue May 27, 2023 · 0 comments
Open

ValueError: Value should be 32 bytes long #343

ltfschoen opened this issue May 27, 2023 · 0 comments

Comments

@ltfschoen
Copy link

ltfschoen commented May 27, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant