Learn everything about Polkadot, Kusama chains, Substrate Pallets, ink! etc.
-
History:
- Started as Parity Technologies & now called as Polkadot Foundation.
-
Substrate FRAME version (current): 3.0.0
-
Substrate ink! version (current): 4.0.0
-
Layer-0 i.e. L0
-
Polkadot can have a TPS of 100k to 1M considering the parachains (around 100).
-
chains (mainnet or testnet):
- Relay chain
- main/central chain
- validators (297 approx.) ensuring the security of the network i.e. Polkadot
- does not support SC (smart contract). It needs to have at least 1 parachain.
- Parachains (100 max.)
- the chains (L1 chains like Ethereum) that are connected to the relay chain. They can have SC.
- The max. number of parachains is 100 supposedly, although this number is not confirmed as not tested yet. But, then it can be worked upon. There can be more parachains if the relay chain is upgraded based on the runtime logic.
- collators (5 approx.)
- they need to stake some auction fee in DOT (held every 6 months) to register a parachain on the relay chain. So, it's a weighted-fee.
- slots
- parachain slot (limited)
- parachain bridge slot
- parathread slot
- the chains (L1 chains like Ethereum) that are connected to the relay chain. They can have SC.
- Relay chain
-
Token details:
- symbol: DOT
- decimal: 10 (formerly it was 12 before 21-aug-2020)
The DOT redenomination took place on 21 August 2020, known as Denomination Day, at block number 1_248_328. Source
- lowest unit: Plancks. 1 DOT = 1e10 Plancks
So, in block explorer, if the balance of an account is
1.1529 MUNIT
, then it's1.1529 * 1e6 UNIT
i.e.1.1529 * 1e6 DOT
i.e.1.1529 * 1e6 * 1e10 Plancks
(including decimals). -
Consensus Algorithm (NPoS):
- voter/nominator:
- Anyone who has min.
10
DOT on Polkadot (0.1 KSM on Kusama). - Max.
50,000
nominators allowed for electing the validators. - Max.
16
validators on Polkadot (24
on Kusama) can be nominated by a nominator. - The staked amount
100 DOT
(say) is divided among the selected validators (say16
or6
) equally i.e.6.25 DOT
each. - A voter can nominate less than
16
validators as well. But, the chances of validators getting selected are less. Also, the rewards are less. - Only the top
256
nominators for a specific validator get paid. - Cons:
- One might loose their DOT in case of electing a malicious validator.
- One might not gain any rewards
- if none of the selected validator is elected.
- if very few validators are elected. So, it's recommended to nominate max.
16
validators. Hence, one needs to do proper research.
- Anyone who has min.
- validator:
- Anyone who has min. 'x' (dynamic, changes over time) DOT on Polkadot to become active validator.
- They need to stake their DOTs to get elected as a validator.
- They can lose their staked DOTs, if they turn out to be malicious.
- One has to verify their decentralized identity on Polkadot. Hence, would get โ mark on their profile. The ones whose identity is under verification would get โ๏ธ (grey color) mark.
- One can be very popular if they are oversubscribed by the nominators.
- voter/nominator:
-
Mainnet:
- relaychains:
- Kusama (new feature launched here 1st),
- Polkadot (at stable stage after feature launched on Kusama)
- relaychains:
-
Testnet:
- relaychain: Rococo
- faucet: Rococo Faucet
- parachain: Canvas, Contracts (by Parity)
- relaychain: Rococo
-
There are 2 ways to develop dApp on a substrate chain:
- M-1: write SC on native parachain/parathread using
ink!
(ink! is a Rust-based eDSL for writing Wasm smart contracts) - M-2: write SC on EVM supported parachain/parathread using
solidity
(solidity is a high-level language for implementing smart contracts)
- M-1: write SC on native parachain/parathread using
-
pay fee with DOT for 2 different types of chains:
- Parachain: weighted fee.
- Parathread: participate on per use i.e. block basis or essentially
pay-as-you-go
.
-
Parachain vs Parathread:
Parachain | Parathread |
---|---|
1. Parachain is always connected. | 1. Parathread is not always connected. |
2. DOT staked, hence weight-fee model | 2. pay per block basis or pay-as-you-go or gas-metering model |
3. supports SC | 3. supports SC |
-
If you think about Polkadot as a giant computer, parachains are like applications that are in physical memory and highly available. Parathreads are like applications that are on disk and can be copied into memory when needed. For those already familiar with how Bitcoin and Ethereum work, users bid to enter a parathread block into the relay chain similar to how users bid to include a transaction in a Bitcoin or Ethereum block.
-
Parathreads are ideal for three types of applications:
- applications seeking an on-ramp to Polkadot,
- applications worried about losing parachain slots, and
- applications that have more reads than writes.
-
Parathreads increases the number of applications that can operate on Polkadot by pooling them to share parachain slots. This will allow more infrastructure chains and improve composability."
Parachains require
20,000 DOT
tokens to be staked in order to secure a slot. And these projects don't have enough budget can use Parathreads so that they can come back to the parachain slot auction later.
graph LR
Parachain --when less budget--> ParaThread --when more budget--> Parachain
-
Polkadot vs SC: "Polkadot does not use a gas-metering model, but a weight-fee model, meaning Parachains do not have a gas-metered model in their logic. Parachains can implement powerful programming languages. Better put, parachains try to be proactive, while smart contract platforms are event-driven."
-
EVM vs WASM:
EVM | WASM |
---|---|
it isnโt as fast as it should be and directly impact network efficiency | it expands the supported languages that a developer can write a smart contract in, such as Rust, C/C++, C#, and Typescript. |
it uses opcodes that are not optimized for different hardware platforms. | it is is highly performant. |
The support and reach for developing smart contracts are limited. | it is optimized for different hardware platforms. |
- Pallet: module that trigger functionality on a parachain. Typically like system contracts on a L1 Blockchain.
- Follow this
- People interacting with parachains via smart contracts won't have to have DOT tokens to pay for fees. Instead, they'll pay in the native token of the parachain. So, with this feature user would not need to have DOT tokens in order to make any transaction on parachain. This is a huge step towards mass adoption because it would be easier for the user to interact with the parachain rather than having to buy DOT tokens.
- In order to reserve limited parachain slots, parachains must stake DOT tokens. The more DOT tokens staked, the higher the parachain's priority in the auction. Although their is a minimum DOT tokens (say 1M) to be staked.
- Now, the concern is to how to arrange that much amount of DOT tokens.
- One can buy DOT tokens from the market or already held DOT tokens.
- Ask the investor to stake DOT tokens as loan on your behalf. There is a guarantee of getting the money back as it would happen on-chain via pallets.
- Ask the community to stake DOT tokens via crowdloan on your behalf. There is a guarantee of getting the money back as it would happen on-chain via pallets.
Has partnered with Alchemy
Hub for DeFi in Polkadot, Kusama.
- Acala is on Polkadot
- Karura is on Kusama
EVM โ
Switch to any L0, parachain, parathread network.
- Subscan
- Beautiful looking UI/UX for viewing txns, blocks, accounts for Polkadot, Kusama, Rococo relaychain & parachains & testnets.
- Polkadot.js
- Polkascan
- available for only Polkadot, Kusama, no local node support
- IPFS based Polkadot.js
- relatively slow
These are the wallets (like Metamask):
URL: https://wiki.polkadot.network/docs/build-wallets
Browser extension: https://chrome.google.com/webstore/detail/polkadot%7Bjs%7D-extension/mopnmbcafieddcagagdcbnhejhlodfdd/related
Mobile wallets: https://polkawallet.io/
- Substrate allows the different features of Polkadot as it allows a modular design with pallets. Using different pallets like balance, account, transaction, block, consensus one can create own parachain.
- Substrate (by default) has a
WASM
runtime but it also allows to create a custom runtime likeEVM
using pallet programming. So, if someone wants to create aEVM
runtime for running EVM SCs, then a set of pallet (account, balance, consensus, etc.) has to be created in order to join them together & form the required runtime for a parachain with that runtime. FRAME
is the library which is used to build DApps.
There are different FRAME pallets to choose from in order to add into runtime.
For networking, substrate use libp2p
protocol (developed by IPFS creators).
Using this template, we can start a chain locally. repo.
Using the front-end template, we can view the information on a website. repo.
The development workflow to pallet:
where, sp: substrate primitive
, sc: substrate client
In Polkadot, in order to secure a slot, a project/parachain has to bid in the auction. This auction has no end time. The winning is completely based on the highest amounts in terms of ranking.
This auction is similar to Candle auction in 16th century.
There is also a feature of crowdloan where anyone holding DOT can lend to project/parachain. And after the auction period is over, the DOTs are returned back to the owners permissionlessly.
- Substrate
- playground: setup w/o local PC.
- Telemetry: View all the nodes running polkadot.
- Polkadot explorer
- kusama explorer
- Substrate Utilities by Shawn
- CLIs
All web3 packages here:
- All the new features are deployed on Kusama 1st & then it gets deployed on Polkadot.
- There are plans to brige both these relay chains
There are message protocols which are used for communicating b/w chains. E.g. XCM, XCMP
- XCM: Cross Consensus Message format
- XCMP: Cross Chain Messaging Protocol
The collators give the proof (parachains' block when reached finality i.e. 'proof of validity') to the validators who then add to the relay chain.
Each parachain has 2 options of adding blocks into the relay chain:
- slot (
stake DOT
& secure position) - parathread pool (
pay-as-you-go
model)
It stays in merkle tree.
Here, only the nodes which have been changed in terms of data, those gets added in hash. The figure above shows the transition state.
A receipt is used to put into the blocks of relay chain
There is a set_code
function which allows to upgrade the network.
It shows comparo b/w legacy & polkadot blockchains.
By ParityTech:
- Substrate (The platform for blockchain innovators): https://github.com/paritytech/substrate
- Cumulus (Write Parachains on Substrate): https://github.com/paritytech/cumulus
- Polkadot (Polkadot Node Implementation): https://github.com/paritytech/polkadot
- Substrate node (relaychain) template: https://github.com/substrate-developer-hub/substrate-node-template
- Substrate parachain template: https://github.com/substrate-developer-hub/substrate-parachain-template
- Substrate node FE template: https://github.com/substrate-developer-hub/substrate-front-end-template
- Awesome Substrate (official): https://github.com/substrate-developer-hub/awesome-substrate
- ink! (Smart Contract Language for Substrate): https://github.com/paritytech/ink
- Lightweight, efficient, binary serialization and deserialization codec: https://github.com/paritytech/parity-scale-codec
SCALE is a light-weight format which allows encoding (and decoding) which makes it highly suitable for resource-constrained execution environments like blockchain runtimes and low-power, low-memory devices.
By others:
- zhubaiyuan/awesome-substrate: https://github.com/zhubaiyuan/awesome-substrate
- A Substrate pallet implementing role-based access control and permissions for Substrate extrinsic calls: https://github.com/gautamdhameja/substrate-rbac [TODO: add test to this repo]
- https://github.com/darwinia-network/darwinia
- Substrate Open Runtime Module Library (ORML): https://github.com/open-web3-stack/open-runtime-module-library
- ORML Currencies pallet: https://github.com/open-web3-stack/open-runtime-module-library, package: "orml-currencies"
- ORML traits
- ORML tokens
- Lightweight client for Substrate-based chains, such as Polkadot and Kusama: https://github.com/smol-dot/smoldot
- Subwasm is a cli utility to inside a Substrate WASM Runtime: https://github.com/chevdor/subwasm
- Pallets by Integritee network: https://github.com/integritee-network/pallets
- DIA Oracle pallet: https://github.com/pendulum-chain/oracle-pallet
- DeFi based parachain that has DeFi pallets available as a tool:
- Permission pallet: https://github.com/sora-xor/sora2-network/tree/master/pallets/permissions
- DEX manager pallet: https://github.com/sora-xor/sora2-network/tree/master/pallets/dex-manager
- Orderbook pallet: https://github.com/sora-xor/sora2-network/tree/master/pallets/order-book
- Multicollateral Bonding curve pool pallet: https://github.com/sora-xor/sora2-network/tree/master/pallets/multicollateral-bonding-curve-pool
- Pool xy=k pallet: https://github.com/sora-xor/sora2-network/tree/master/pallets/pool-xyk
- trading pair pallet: https://github.com/sora-xor/sora2-network/tree/master/pallets/trading-pair
- A tutorial for building a Decentralized Exchange Pallet using the Polkadot SDK
Raised a question over stackexchange.
- Cause: Doesn't perform as expected. Seen this error on Polkadot JS Apps UI.
- Solution: Just reload the page. Use cmd + r to reload the App.
2. error[E0275]: overflow evaluating the requirement <Runtime as pallet_voting::Config>::MaxProposalLength == _
- Cause: This error is seen when we try to run the
cargo check -p node-template-runtime
command orcargo build -r
command. - Solution: We need to remove
Self
in the code like this:
Before:
parameter_types! {
pub const MaxProposalLength: u32 = 100;
pub const MinProposalLength: u32 = 5;
}
/// Configure the pallet-voting in pallets/voting.
impl pallet_voting::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxProposalLength = Self::MaxProposalLength;
type MinProposalLength = Self::MinProposalLength;
}
After:
parameter_types! {
pub const MaxProposalLength: u32 = 100;
pub const MinProposalLength: u32 = 5;
}
/// Configure the pallet-voting in pallets/voting.
impl pallet_voting::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxProposalLength = MaxProposalLength;
type MinProposalLength = MinProposalLength;
}
-
Cause: This error is seen during runtime build as there is no type annotation used the variables.
307 | pub const MaxProposalLength = 100; | ^ no rules expected this token in macro call
-
Solution: We need to add type annotation to the variables like this:
Before:
// runtime/src/lib.rs
parameter_types! {
pub const MaxProposalLength = 100;
pub const MinProposalLength = 5;
}
After:
// runtime/src/lib.rs
parameter_types! {
pub const MaxProposalLength: u32 = 100;
pub const MinProposalLength: u32 = 5;
}
-
Cause: The compiler thinks that
T
must also be bounded byMaxEncodedLen
, even thoughT
itself is not being used in the actual types. -
Solution:
-
M-1: Add
#[codec(mel_bound())]
to the type definition:// Struct for holding Kitty information. #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(T))] #[codec(mel_bound())] // <---------------- Here pub struct Kitty<T: Config> { pub dna: [u8; 16], // Using 16 bytes to represent a kitty DNA pub price: Option<BalanceOf<T>>, pub gender: Gender, pub owner: AccountOf<T>, }
-
M-2: Add generic type to the type definition:
// Struct for holding Kitty information. #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct Kitty<Account, Balance> { pub dna: [u8; 16], // Using 16 bytes to represent a kitty DNA pub price: Option<Balance>, pub gender: Gender, pub owner: Account, }
-
- Cause: Didn't use
pallet_balances
inimpl
block offrame_system
forTest
runtime - Solution: Add
pallet_balances
inimpl
block offrame_system
forTest
runtime.
-type AccountData = ();
+type AccountData = pallet_balances::AccountData<u128>;
6. running 1 test thread 'tests::open_fd' panicked at 'get_version_1
called outside of an Externalities-provided environment.'
- Cause: Didn't use
new_test_ext().execute_with(|| {});
inside the test function - Solution: Add
new_test_ext().execute_with(|| {});
inside the test function
Before:
#[test]
fn test_something() {
// Test code
}
After:
#[test]
fn test_something() {
new_test_ext().execute_with(|| {
// Test code
});
}
7. error: the wasm32-unknown-unknown target is not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
Details:
|
235 | / compile_error!("the wasm32-unknown-unknown target is not supported by \
236 | | default, you may need to enable the \"js\" feature. \
237 | | For more information see: \
238 | | https://docs.rs/getrandom/#webassembly-support");
| |________________________________________________________________________^
error[E0433]: failed to resolve: use of undeclared crate or module `imp`
--> /Users/jackson/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.7/src/lib.rs:262:5
|
262 | imp::getrandom_inner(dest)
| ^^^ use of undeclared crate or module `imp`
- Cause: it looks like one of your dependencies tries to generate random numbers.
- Solution: Insert
default-feature = false
into one of your dependency in `Cargo.tomlYou can enable the default features in
[dev-dependencies]
i.e.default-features = true
or remove it altogether as implemented by default, but you should not enable that in[dependencies]
as it might trigger randomization.
// Cargo.toml
[dependencies]
- sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
+ sp-core = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Error details:
Rust WASM toolchain not installed, please install it!
Further error information:
------------------------------------------------------------
Compiling wasm-test v1.0.0 (/var/folders/cw/dc7mkcsd6yx76lscv6w1hpcw0000gn/T/.tmp3NWr2N)
error[E0463]: can't find crate for `std`
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
error: requires `sized` lang_item
libunwind: malformed __unwind_info at 0x18AC83CA8 bad second level page
error: cannot find macro `println` in this scope
--> src/main.rs:3:5
|
3 | println!("{}", env!("RUSTC_VERSION"));
| ^^^^^^^
For more information about this error, try `rustc --explain E0463`.
libunwind: malformed __unwind_info at 0x18AC83CA8 bad second level page
error: could not compile `wasm-test` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `wasm-test` (bin "wasm-test") due to 3 previous errors
------------------------------------------------------------
warning: build failed, waiting for other jobs to finish...
- Cause:
wasm32-unknown-unknown
target is not installed or may be it's installed but due to switching of channels, it's not supported anymore. - Solution: If the error is popping up even after doing
$ rustup target add wasm32-unknown-unknown
&$ rustup target install wasm32-unknown-unknown
then just uninstallrustup
entirely and then reinstall. Build again. It would be fixed now.
- Parity Homepage
- Polkadot Blockchain Academy:
- Polkadot Wiki
- Substrate Homepage
Many pages need to be updated.
- Parity Tech Rust Doc
flowchart
parity[paritytech.github.io] --> devhub[polkadot_sdk_docs]
devhub --> polkadot_sdk
devhub --> reference_docs
devhub --> tutorial
polkadot_sdk --> substrate
polkadot_sdk --> frame
polkadot_sdk --> cumulus
polkadot_sdk --> polkadot
polkadot_sdk --> xcm
-
Polkadot Documentation
This doc has been created with
.rs
files. So, all the markdown based docs has been created inside//!
in.rs
files. The crate name: "polkadot_sdk_docs".Modules:
- guides
- meta_contributing
- polkadot_sdk
- reference_docs
-
Collection of Useful Bridge Building Tools ๐๏ธ: Github
- Polkadot Blockchain Terms
- HOW TO BUILD PARACHAIN ON POLKADOT
- Polkadot Messaging Scheme (XCMP)
- Support: Ask any Q.s here
- Gavin Wood Sees Polkadot as a Global Supercomputer | Polkadot Decoded 2023 โ
- Gavin Wood: Explaining the Polkadot Launch Process โ
- Chainlink | Introduction to Polkadot, Parachains, and Substrate โ
- The Path of a Parachain Block on Polkadot and Kusama Network
- Intro to Substrate codebase and FRAME pallet deep-dive with Joe Petrowski and Shawn Tabrizi โ
- Learn Rust syntax for Substrate | Substrate Seminar โ
- Polkadot and Substrate โ Build Custom Blockchains that can Evolve
- Sub0 Online: ink! 3.0: A Rust & Smart Contracts Love Story
- Polkadot Deep Dives
- Substrate Seminars
- details in this repo
- Substrate Saturday by Polkadot India YT playlist
very down to earth & easy to understand videos. It is a must watch for beginners.
- Substrate Saturday by Polkadot India | Bootcamp 1 | 22.12.21 โ
- Substrate Saturday by Polkadot India | Bootcamp 2 | Session 1 | 22.01.22 โ
- Substrate Saturday by Polkadot India | Bootcamp 2 | Session 2 | 05.02.22 โ
- Substrate Saturday by Polkadot India | Bootcamp 3 | 26.02.22
- Substrate Saturday - Bootcamp Series 2 | Workshop | Ivan Temchenko | 23.07.22
- Substrate Saturday - Bootcamp Series 2 | Episode 5 | 13.07.22
- Substrate Saturday - Bootcamp Series 2 | Episode 1 | 09.07.22
- Substrate Saturday - Bootcamp Series 2 | Episode 2 | 16.07.22
- Substrate Saturday - Bootcamp Series 2 | Episode 4 | 30.07.22
- Substrate Saturday - Bootcamp Series 2 | Workshop | Pierre Ossun | 20.08.22
- Substrate Saturday - Bootcamp Series 2 | Episode 7 | 27.08.22
- Substrate Saturday - Bootcamp Series 2 | Episode 9 | 10.09.22
- Substrate Saturday - Bootcamp Series 2 | Workshop | Faisal Ahmed | 17.09.22 |
- The Future of the Network | Polkadot Blockchain Academy 2023 โ
- What Will the Next Generation of Dapps Look Like? | ETHDenver '23 โ
- ๐ฎ Runtime Development
- It mainly focuses on the runtime development of substrate using FRAME v2. Especially for the beginners, it is a must watch. Also, it's going to give you a good idea about the runtime development of substrate in terms of journey that how it has evolved from FRAME v1 to FRAME v2.
- Centrifuge: From Solidity To Substrate | Sub0 2022 โ
- Building blockchains the easy way | Substrate Seminar โ
- Set-up tips, key concepts and how to build with them | Substrate Seminar
- Starkware builds on Substrate w/ Louis Guthmann
- Madara, a new Substrate-based sequencer for Starknet appchains (with Abdelhamid Bakhta)
- Episode 229 - Going Cross-Chain with Polkadotโs XCM