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.

How do we convert bytes from encoded number

See original GitHub issue

In substrate(rust), type of encoded value is Vec<u8> and in polkadot-js, type of encoded value is Uint8Array. How to convert a value of type Uint8Array to value of type Vec<u8> or Bytes?

Error code 1

let u8_1 = api.registry.createType("u8", 1).toU8a();
let u32_25 = api.registry.createType("u32", 25).toU8a();

Error message is : mockNumericCondtion: error message is MustBeDecodable,

This error defined

let number: u8 = Decode::decode(&mut &_query[..]).map_err(|_| Error::<T>::MustBeDecodable)?;

Error code 2

let u8_1 = new Bytes(api.registry, api.registry.createType("u8", 1).toU8a());
let u32_25 = new Bytes(api.registry, api.registry.createType("u32", 25).toU8a());

Error message is: UnhandledPromiseRejectionWarning: Error: Bytes: required length less than remainder, expected at least 2, found 1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thashimoto1998commented, Sep 18, 2020

It worked 😃 Thank you very much!

0reactions
polkadot-js-botcommented, Jun 3, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Number of bytes to encode a number - Stack Overflow
Actually, bytes[0] = 0000 0000 and bytes[1] = 0000 0001 . The number represented by your bytes[] is 511 (decimal). – Stephen C...
Read more >
How to Convert Bytes to String in Python ? - GeeksforGeeks
This method is used to convert from one encoding scheme, in which the argument string is encoded to the desired encoding scheme.
Read more >
How to convert byte[] array to String in Java - Mkyong.com
In Java, we can use new String(bytes, StandardCharsets.UTF_8) to convert a byte[] to a String . // string to byte[] byte[] bytes =...
Read more >
Convert Bytes to a String
Simple, free, and easy to use online tool that converts bytes to a string. No intrusive ads, popups, or nonsense, just a neat...
Read more >
How to convert Python string to bytes? | Flexiple Tutorials
#Using the byte() method # initializing string · bytes ; b'Join our freelance network' 74 · 105 ; #Using the encode method #...
Read more >

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