Questions tagged [substrate]

Substrate is a framework for Blockchain prototyping and development written in Rust.

Substrate is a framework for prototyping and development written in . At its heart, Substrate is a combination of three technologies: , and AfG Consensus. It is both a library for building new blockchains and a skeleton key of a blockchain client, able to synchronize to any Substrate-based chain.

Substrate chains have three distinct features that make them next-generation: a dynamic, self-defining state-transition function (STF), light-client functionality from day one and a progressive consensus algorithm with fast block production and adaptive, definite finality.

The STF, encoded in WebAssembly, is known as the runtime. This defines the execute_block function and can specify everything from the staking algorithm, transaction semantics, logging mechanisms and procedures for replacing any aspect of itself or of the blockchain’s state (governance). Because the runtime is entirely dynamic all of these can be switched out or upgraded at any time. A Substrate chain is very much a living organism.

335 questions
13
votes
1 answer

When should I build a Substrate Runtime Module versus a Substrate Smart Contract?

What are the differences between developing a Substrate Runtime Module and a Substrate Smart Contract (for example with the ink! language)? What are some examples of applications which are best written in one form or the other?
mountbranch
  • 174
  • 7
11
votes
1 answer

In Substrate, What is the difference beteween Babe, Aura, and Grandpa

Substrate supports "pluggable consensus" so a developer can choose from among several consensus algorithms. It comes standard with four algorithms: Aura Babe Proof of Work Grandpa Some of these (eg babe and grandpa) can even be used together in a…
JoshOrndorff
  • 1,029
  • 5
  • 17
9
votes
1 answer

How do you convert between Substrate specific types and Rust primitive types?

Using the Substrate blockchain framework, how can I convert between Substrate specific types and Rust primitive types and vice versa? For example: Convert a time (T::Moment) to a u64 Convert a u64 to a T::Balance etc...
Shawn Tabrizi
  • 9,495
  • 1
  • 22
  • 50
8
votes
1 answer

In Substrate is there a way to use storage and functions from one custom module in another?

I have seen the Substrate Tutorial on creating crates of individual Substrate Runtime modules here in order to re-use the functionality, but I wondered if there is a way for one custom module to access the storage or functions from another custom…
T9b
  • 2,576
  • 4
  • 26
  • 45
6
votes
1 answer

What order is `on_initialize` invoked across different modules in a Substrate runtime?

I need to be sure that the on_initialize handler for a specific module runs before the same handler before all other modules in my runtime. a) How do ensure this? b) Is there some compile or runtime check I can enforce to absolutely guarantee that…
5
votes
1 answer

In Substrate, what's the difference between `spec_version` and `authoring_version`?

Each Substrate runtime has a RuntimeVersion. The fields in this RuntimeVersion struct indicate when various aspects of the runtime change and each field has its own semantics described in those docs. I'm not sure what authoring_version means and…
JoshOrndorff
  • 1,029
  • 5
  • 17
5
votes
1 answer

How to activate Substrate GRANDPA finalization?

I want to start a chain with Babe/Grandpa consensus. I'm able to start block production using Toolbox->RPC->author->insertKey() in UI. But I don't know how to start block finalization. I've tried setting grandpa keys the same way I sat babe keys in…
5
votes
1 answer

How to correctly upgrade a runtime on Substrate node?

Followed the create a first substrate chain it all works good. And then I want to go one step further to customize my on the demo.rs file, here is what I am doing: Totally replace code in demo.rs with code here, there is event involved now . update…
Haven
  • 6,444
  • 5
  • 21
  • 34
5
votes
2 answers

How to get the roothash or a proof from a child trie in substrate?

According to the example here, I see one could use the srml_support::storage::child API to create a merkle sub trie out of arbitrary data. But how can we get the merkle root or a proof for a particular leaf using this? I see the API doesn't provide…
vim
  • 1,019
  • 9
  • 20
4
votes
1 answer

Runtime Building: String not found in this scope

A common problem substrate developers might run into: developing a custom pallet to store the mapping into storage with common types, such as String. As an example: #[derive(Encode, Decode, Clone, Default, RuntimeDebug)] pub struct ClusterMetadata…
NukeManDan
  • 332
  • 1
  • 11
4
votes
2 answers

What is the cost of event storage in substrate?

While implementing my chain logic I was wondering whether to use events at all since they might cost the node extra storage for the event logs. What is the actual storage cost involved here? Do the logs get purged automatically at some point?
vim
  • 1,019
  • 9
  • 20
4
votes
3 answers

How to print out tracing message in Substrate runtime development

When working on Parity Substrate runtime development, how can I print out debug message for tracing and inspecting my variables?
Jimmy Chu
  • 842
  • 6
  • 21
3
votes
1 answer

How do you write a system test for your runtime?

Hi I am developing a runtime using Substrate-FRAME and I would like to know how can I write a system test for my runtime? The main purpose of writing a system test is to ensure that the final build is fulfilling all of the required specifications…
Jdawg287
  • 45
  • 3
3
votes
1 answer

How to implement background thread in Substrate?

Let's imagine I want to design a system similar to crowdfunding or to the auction. There is a fixed period of time for which such an event is running. Can I start a background thread that will periodically check whether the end time if the event has…
Petr Mensik
  • 24,455
  • 13
  • 84
  • 111
3
votes
1 answer

How can I convert the block number into the Integer type in substrate module?

I'm testing the substrate off-chain worker, what I want to do is receive the current block number, and then do some calculation, just like the below code if (get_block / 10 == 0), and I get some error. How can I convert the block number into the…
leojail
  • 65
  • 1
  • 5
1
2 3
22 23