Skip to main content
13 votes
Accepted

Why do I need to use SCALE codec?

There are a few reasons, some historical and others not. Main reasons: Simple to define. Not Rust-specific. Consensus critical/bijective; one value will always encode to one blob and that blob will ...
Gav's user avatar
  • 2,681
13 votes

Why do I need to use SCALE codec?

SCALE - Simple Concatenated Aggregate Little-Endian is a binary encoding. In contrast to encodings like JSON, it just stores the data without any information about the structure of the data. This has ...
bkchr's user avatar
  • 11.3k
10 votes

Why do I need to use SCALE codec?

SCALE codec is an efficient serializer and deserializer built for Substrate chains. It is lightweight, platform agnostic and enables compact encoding of Rust types and data structures. In order to ...
Sacha Lansky's user avatar
  • 2,640
10 votes

Reason for yanked `parity-scale-codec` versions 3.0-3.1.1?

To expand on wigy's answer, basically the bitvec type and lsb/msb identifier were reversed. To put this into context, instead of the metadata types returning BitVec<u8, lsb> it returned BitVec&...
Jaco's user avatar
  • 5,865
9 votes
Accepted

What are the Steps for Encoding an Extrinsic in Substrate?

More generally, if you were to SCALE encode a signed transaction, you'd follow these steps: Combine the call, extra and additional data and SCALE encode it: call data: the pallet index, call index ...
Sacha Lansky's user avatar
  • 2,640
7 votes
Accepted

PolkadotJS how to properly setup api for custom RPC invocation

In general, issues like this are due to incorrectly encoding Vec in SCALE. All Vecs are prepended with their length (section Vectors (lists, series, sets)). A collection of same-typed values is ...
Shawn Tabrizi's user avatar
  • 16k
7 votes

What is the role of `#[scale_info(skip_type_params(T))]`?

The answer to this question is similar to the answer here: How to fix `parity_scale_codec::MaxEncodedLen` is not implemented for `T`? Basically, Rust macros are not that intelligent. In the case of ...
Shawn Tabrizi's user avatar
  • 16k
7 votes
Accepted

Ink cannot derive SpreadLayout and SpreadAllocate for simple struct and enum

SpreadAllocate can't be derived for the enums(issue), so you should implement it manually. You are deriving SpreadLayout wrong=) #[cfg_attr(feature = "std", derive(...)] means - derive it ...
Green Baneling's user avatar
6 votes
Accepted

How to decode an unsigned transaction using polkadot.js

The api provides a shortcut helper for this - api.tx(<hex bytes>) will decode/reconstruct it.
Jaco's user avatar
  • 5,865
6 votes
Accepted

Reason for yanked `parity-scale-codec` versions 3.0-3.1.1?

Based on the diffs, upgrading to bitvec 1.0 broke the serialization format of those types that used bit vectors. Version 3.1.2 is the first release that fixed that regression, so to be on the safe ...
wigy's user avatar
  • 375
5 votes
Accepted

How does `#[codec(mel_bound())]` work?

skip_type_params(T) boils down to the same as mel_bound(), both will have an empty where-bound for the implementation of MaxEncodedLen. The advantage of skip_type_params is that if there are more ...
bkchr's user avatar
  • 11.3k
4 votes
Accepted

How can I decode an extrinsic or event dynamically in rust?

Regarding dynamic event decoding, this is something that cargo-contract does. It is not easily reusable at the moment but feel free to copy the code and use it for inspiration. Start here. The other ...
Andrew Jones's user avatar
4 votes
Accepted

Decoding events with Rust

There's two ways of decoding events in rust: statically typed and dynamically typed. Statically you can use subxt to decode events from this SCALE encoding - it's done here for example. Basically ...
Squirrel's user avatar
  • 3,849
4 votes
Accepted

What is the difference between Metadata and FRAME-Metadata?

The metadata provides essential information regarding the substrate blockchain you are connecting to. It is unique to that chain's runtime. The chain's runtime metadata includes information such as ...
Bruno's user avatar
  • 8,365
4 votes
Accepted

Implications of invalid encoded extrinsic calls

Great question! What are the security implications of panicking inside the WASM when an extrinsic can not get decoded successfully? Before a transaction enters the tx pool the tx is validated using ...
Daan van der Plas's user avatar
3 votes

How do we work with polkadot-js enums in TypeScript?

Not able to reproduce your problem, but by looking at the code i am thinking it should be something like this: if (result.isOk) { const decoded = this.contract.abi.registry.createType(`Result<...
Andreea Eftene's user avatar
3 votes

Implement MaxEncodedLen for Nested Origin

You're right that this kind of construct is not directly supported by MaxEncodedLen because, just like Vec<u8>, it has no strict limit to the encoded length. I wouldn't really trying to work ...
Gav's user avatar
  • 2,681
3 votes
Accepted

Create hex encoded call (for XCM transact call) in javascript?

When you construct via api.tx.* is creates an unsigned extrinsic. So basically you want the call-only part of that. // output as hex const encoded = u8aToHex( // add length to the U8a (double-...
Jaco's user avatar
  • 5,865
3 votes

How to create a tuple type using polkadot.js api

Tuple types are specified in the same way they are in Rust, i.e. (AccountId, u32) will yield a tuple with AccountId and u32. These are all string values, i.e. MyTuple: "(AccountId, u32)", ...
Barto's user avatar
  • 584
3 votes

How to solve 'Invalid transaction version'?

For the sake of answering this question (though I have replied to you elsewhere already on this topic); The transaction format is not just a simple SCALE encoding of some details. In rust pseudocode, ...
jsdw's user avatar
  • 1,335
3 votes
Accepted

Can SCALE compact encoding be used with `Option<T>`? If so, how exactly?

This happens because you apply #[pallet::compact] attribute to the type Option<u128>. u128 can be represented as compact. Option<u128> can't though, since it's an option. In this case, to ...
pepyakin's user avatar
  • 2,174
3 votes
Accepted

How can we use struct instead of tuple in pallet storage?

If you use FRAME and the corresponding macros to define storage, then in that case the values stored will be serialized using the SCALE encoding. SCALE encoding is equivalent between structs and ...
pepyakin's user avatar
  • 2,174
2 votes
Accepted

Backward compatible changes in the runtime

The runtime itself is stored on-chain. This is what actually executes the extrinsics for block inclusion. This means that all clients run the exact same on-chain code at any single point in time to ...
RosaryBeads's user avatar
2 votes

What are the Steps for Encoding an Extrinsic in Substrate?

As most Substrate builders are Rust natives, the best examples of extrinsic formation and submission can be found in subxt. For your specific example, sp_runtime::traits::SignedExtension can be ...
Nuke's user avatar
  • 1,842
2 votes
Accepted

Scale codec f64 support

Basically this question boils down to: Can you use floating point numbers or math in the Runtime? While SCALE could deterministically encode and decode floating point types, the runtime can't ...
Squirrel's user avatar
  • 3,849
2 votes

Scale codec: Is there a way to extract an enum's arm's codec index value?

No there is no way to extract these information from a type. I think in your case you should just add a function to Block get_version.
bkchr's user avatar
  • 11.3k
2 votes

What's the difference between `transaction_version` and `EXTRINSIC_FORMAT_VERSION`?

The transaction_version is a field in the RuntimeVersion struct, specific to a runtime implementation. A bump to this value happens whenever there's a change to a pallet's runtime index and/or when ...
Sacha Lansky's user avatar
  • 2,640
2 votes
Accepted

Stable scale encoded events from ink contract

Currently there is no way to make the encoding independent of the ordering. As you say a internal enum is generated with the event structs as variants and they are just added in the order they appear. ...
Andrew Jones's user avatar
1 vote
Accepted

What is the purpose of the `contracts_runtime.scale` file in the `cargo-contracts` repository?

The metadata was downloaded from a running substrate-contracts-node and is used to generate the APIs and types required for constructing contract extrinsics and querying storage from a compatible node....
Andrew Jones's user avatar
1 vote

Decode preimages Bounded Dispatchable Call on a client side

The Bounded that you got there already is decoded. What you want to do now is to decode the content of the Bounded<Call>. I just tried that locally and it did not work but could work with your ...
Oliver Tale-Yazdi's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible