Skip to main content

Questions tagged [scale-codec]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
15 votes
3 answers
706 views

Why do I need to use SCALE codec?

SCALE codec is used to encode and decode data for Substrate runtimes. Why is it the top choice in Substrate and can I implement my own SCALE library?
Sacha Lansky's user avatar
  • 2,640
12 votes
1 answer
313 views

PolkadotJS how to properly setup api for custom RPC invocation

I'm playing around with custom RPC endpoints exposed from my substrate node, but I'm encountering an issue when trying to call it with polkadotjs. Initially, my endpoint only accepted a single ...
Tony's user avatar
  • 527
10 votes
2 answers
669 views

What are the Steps for Encoding an Extrinsic in Substrate?

Substrate introduces some unique concepts such as unsigned transactions and signed extensions. What are the steps for encoding an extrinsic in Substrate? What are the specific details that relate to ...
Dan Forbes's user avatar
7 votes
2 answers
80 views

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

I noticed that the parity-scale-codec versions 3.0.0, 3.1.0 and 3.1.1 have been yanked: https://crates.io/crates/parity-scale-codec/versions. The changelog of the crate doesn't contain any information ...
cmichi's user avatar
  • 2,800
7 votes
1 answer
61 views

Backward compatible changes in the runtime

If I add a new field to a struct that is not stored in storage but used as a parameter to an extrinsic, will it break decoding if a node with the changed runtime is syncing (i.e. executing older ...
Nahu's user avatar
  • 347
7 votes
0 answers
93 views

Why do clients have to hardcode the extra types in the registry?

Context: I'm experimenting with an H160-address based substrate and I'm doing it from scratch (it's not a moon* or frontier template fork). It's reasonably trivial to make changes to the substrate ...
Farcaller's user avatar
  • 158
6 votes
2 answers
270 views

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

#[derive(Encode,Decode,TypeInfo) #[scale_info(skip_type_params(T))] Pub struct Asset<T:Config> { Id:### Name:## } So in the above example if you don't include the second macro. The compiler ...
Mrisho Lukamba's user avatar
6 votes
1 answer
138 views

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

When declaring types, with generic parameters, to be stored in runtime storage, it’s common to see this pattern #[derive(Encode, Decode, MaxEncodedLen, TypeInfo)] pub struct MyItem<TypeA, TypeB> ...
Angelo's user avatar
  • 501
5 votes
1 answer
151 views

What is the difference between Metadata and FRAME-Metadata?

What is the difference between Metadata and Metadata Type Definitions in Substrate? Also, when I do the state_getMetadata RPC call I get the metadata. It is rather long. Is there a way to cache this ...
PaperFrog's user avatar
  • 495
5 votes
0 answers
95 views

I want to use Parity SCALE codec in Solidity? Is there any implementation of scale codec to decode bytes?

I want to decode bytes on the Solidity side that was decoded with scale codec. Is the any implementation of scale codec (decode) on the Solidity side?
rust.dev's user avatar
  • 519
4 votes
1 answer
74 views

Implications of invalid encoded extrinsic calls

We are seeing the following error whenever an invalidly encoded but properly signed extrinsic is submitted in our substrate based chain. { "jsonrpc": "2.0", "error&...
Aramik M's user avatar
  • 139
4 votes
1 answer
507 views

Decoding events with Rust

If I make a request to get events in a particular block using web UI, I get a nice human-readable response: I've made an RPC call to get the same data { "id": 1, "jsonrpc":...
Amir Boziev's user avatar
4 votes
1 answer
260 views

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

How can I decode an extrinsic or event dynamically in rust? (I want to be able to decode across all parachains) A lot of the heavy lifting seems to be frame-metadata and scale-info. There's a desub ...
Squirrel's user avatar
  • 3,849
3 votes
1 answer
337 views

Ink cannot derive SpreadLayout and SpreadAllocate for simple struct and enum

When developing Ink! smart contracts I found that SpreadLayout and SpreadAllocate cannot be derived for simple structs or enums that are members variables of the contract and I have to implement the ...
mastro's user avatar
  • 217
3 votes
1 answer
94 views

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

I can't find anything on how to use the compact encoding of integers with Option<...>. Is this possible? And to elaborate, if I do something like this: #[pallet::call] ... { fn ...
mkl's user avatar
  • 344
3 votes
1 answer
72 views

Scale codec f64 support

What is the reason that the SCALE codec does not support Encode and Decode of f64 types?
Mathis Wellmann's user avatar
3 votes
2 answers
32 views

Is there any way to extract "method" and "params" of unchecked extrinsic using ScaleCode/TypeInfo traits?

I'm wondering if there is any way to extract information about method and parameter of Extrinsic(Unchecked/CheckedExtrinsic) using TypeInfo and Scale codec. In polkadotJs there is toString method on ...
Mateusz Nowakowski's user avatar
3 votes
0 answers
19 views

Why is the index of a pallet a u32(usize) instead of u8 when queried?

I'm implementing a flow where I first ask what index a pallet has with the QueryPallet xcm instruction, and then construct a call to use with Transact. I see that to construct manually an encoded call ...
Juan Ignacio Rios's user avatar
3 votes
0 answers
50 views

After using set_code_hash to upgrade contract, when decode on the new Storage,why there wont has error of "Not enough data to fill buffer"

I'm learning how to upgrade ink! contract,and have some question: Eg:old contractA, storage define is #[ink(storage) pub struct MyContract { a: u32, } new contractB,storage define is #[ink(...
ruarua's user avatar
  • 31
2 votes
1 answer
358 views

How to decode an unsigned transaction using polkadot.js

If I have some unsigned transaction, eg 0x040300865ea... and I wanted to decode it into a format like: method: "balances", section: "transfer": ... Is there a way to do that using ...
Bread's user avatar
  • 95
2 votes
2 answers
92 views

Implement MaxEncodedLen for Nested Origin

orml-authority implements a mechanism to allow origin to dispatch calls after and only after a delay. This is implemented using a pallet origin DelayedOrigin. The DealyedOrigin references the original ...
Bryan Chen's user avatar
2 votes
1 answer
92 views

How to create a tuple type using polkadot.js api

I am trying to create a tuple. I know we can create an enum by defining the type as MyEnum: { _enum: { 'account': String, 'accountId': 'u128' ...
Emmanuel Thomas's user avatar
2 votes
1 answer
45 views

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

I am working on a pallet in which there is storage in which I am using a tuple. Can we use a struct instead of a tuple in the storage of pallet? if yes is there any reference to how we can use it?
Pankaj's user avatar
  • 2,021
2 votes
1 answer
55 views

Stable scale encoded events from ink contract

How to obtain a stable encoding of emitted events from a smart contract? I have a smart contract which emits events when these events are later fetched from the chain: #[ink(event)] pub struct ...
Simson's user avatar
  • 1,201
2 votes
1 answer
69 views

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

Substrate has the concept of a transaction_version and an EXTRINSIC_FORMAT_VERSION. What are these used for and when are they changed?
Sacha Lansky's user avatar
  • 2,640
2 votes
1 answer
80 views

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

Using scale, an enum can be written like this: #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] pub enum Block { #[codec(index = 101)] V1(BlockV1), } The #[codec(index = 101)], the 101 ...
The Quantum Physicist's user avatar
2 votes
2 answers
129 views

Decode preimages Bounded Dispatchable Call on a client side

I'm using Bounded trait from preimages frame that allows to store dispatchable calls, e.g. similar to the one that is used in pallet-democracy: pub type CallOf<T> = <T as frame_system::Config&...
Oleg Kalenik's user avatar
2 votes
1 answer
44 views

How to provide argument to storage call in subxt?

In polkadotjs I have following code: const opts = [{"UniqueIdenfier1":[0,"challengeprofile"]}] let data = api.query.templateModule.periodName( ...opts, ...
Amiya Behera's user avatar
1 vote
1 answer
132 views

How to solve 'Invalid transaction version'?

use std::any::Any; use std::io; use subxt::*; use subxt::{ClientBuilder,DefaultConfig, DefaultExtra}; use subxt::codec::Decode; use crate::sp_runtime::OpaqueExtrinsic; use sp_runtime::{ generic::{ ...
PaperFrog's user avatar
  • 495
1 vote
2 answers
15 views

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

Cargo Contract is a popular tool for developing ink! contracts. This tool is known to work well with the substrate contracts node, and I thought it should work with other chains that support pallet ...
JoshOrndorff's user avatar
  • 1,201
1 vote
0 answers
14 views

DOT, KSM transfer sign payload order

I want to know the scale codec order for sign payload cause currently I can't transfer WND, KSM right now currently my codec order is method call -> era -> nonce -> tip -> specVer -> ...
Bomax Chen's user avatar
1 vote
0 answers
47 views

How to decode contract storage returned data

How do i decode this Hex string to String. It is storage data returned from a contract, using Polkadot-JS. { Ok: { flags: [], data: '...
Woodfish's user avatar
  • 121
0 votes
1 answer
196 views

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

I used typegen to generate my types from definitions. Definition Person: { status: 'Status', balance: 'u128', }, Status: { _enum: ['Active',...
forgetso's user avatar
  • 1,514
0 votes
1 answer
161 views

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

I'm trying to create the encoded element for an XCM V0 transact call such as: const message = { V0: { Transact: { originType: "Native", ...
lucgerrits's user avatar
0 votes
1 answer
33 views

How can I properly use scale::Decode to get consistent results?

I'm trying to process a result from a contract call using what's here. It works totally fine when I'm trying to get a u32 result from an ink_e2e test. E.g. // -- Snip -- let number_of_items = client ...
Kofi's user avatar
  • 143
0 votes
1 answer
26 views

How to construct the data structure with correct values for their attributes within a Pallet for data submitted by a polkadotJS app

Client App creates an Input as follows using polkadotJS to submit to Substrate Module as follows import { ApiPromise, WsProvider } from '@polkadot/api'; const { Keyring } = require('@polkadot/keyring')...
Kalanamith's user avatar
0 votes
1 answer
244 views

How to properly decode a SCALE-encoded string using polkadot-js?

Using @polkadot-js/api, one can encode a string aabbcc into 0x18616162626363 > u8aToHex(api.createType('String', "aabbcc").toU8a()) "0x18616162626363" I know that SCALE ...
btwiuse's user avatar
  • 291
0 votes
1 answer
117 views

Scalecodec: How can I get the equivalent of Decode in Python, instead of DecodeAll?

When using the Python script: timestamp = ScaleDecoder.get_decoder_class('Timestamp', ScaleBytes(timestamp_bytes_array)).decode() it seems that the decoder expects the size of the array to be exactly ...
The Quantum Physicist's user avatar
0 votes
1 answer
24 views

KSM, WND transfer transaction fail, but DOT success

I used the same program, the same fullnode version, and the same Substrate API sidecar version to submit transfer transactions for DOT, KSM, and WND. Only DOT was successful. Two months ago, DOT, KSM, ...
Bomax Chen's user avatar
0 votes
0 answers
18 views

What is the usecase of `PassBy` trait bound

While working on types between Runtime and Host functions, types going from Runtime to host function requires a PassBy trait bound while types going from Host function to Runtime does not need that ...
vedhavyas's user avatar
  • 155
0 votes
1 answer
72 views

How to get human-readable ASTR balance in Golang

This question is continued from How to get ASTR balance via json rpc. I understood calculating StorageKey from Publickey is needed. It seems that calculating StorageKey and decoding rpc-json responses ...
user3563's user avatar