You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/md/en/docs/tutorials/build-application-logic/add-a-pallet.md
+75-63
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,8 @@ As you saw in [Build a local blockchain](/tutorials/build-a-blockchain/build-loc
15
15
This tutorial introduces the basic steps for adding a new pallet to the runtime for the node template.
16
16
The steps are similar any time you want to add a new FRAME pallet to the runtime.
17
17
However, each pallet requires specific configuration settings—for example, the specific parameters and types required to perform the functions that the pallet implements.
18
-
For this tutorial, you'll add the [Nicks pallet](https://paritytech.github.io/substrate/master/pallet_nicks/index.html) to the runtime for the node template, so you'll see how to configure the settings that are specific to the Nicks pallet.
19
-
The Nicks pallet allows blockchain users to pay a deposit to reserve a nickname for an account they control. It implements the following functions:
20
-
21
-
- The `set_name` function to collect a deposit and set the name of an account if the name is not already taken.
22
-
- The `clear_name` function to remove the name associated with an account and return the deposit.
23
-
- The `kill_name` function to forcibly remove an account name without returning the deposit.
18
+
For this tutorial, you'll add the [Lottery pallet](https://paritytech.github.io/polkadot-sdk/master/pallet_lottery/) to the runtime for the node template, so you'll see how to configure the settings that are specific to the Lottery pallet.
19
+
The Lottery pallet allows blockchain users, just like a normal lottery system, to "buy a ticket", which is used to fund the pot. Then, is reallocated to a single user.
24
20
25
21
Note that this tutorial is a stepping stone to more advanced tutorials that illustrate how to add pallets with more complex configuration settings, how to create custom pallets, and how to publish pallets.
26
22
@@ -46,7 +42,7 @@ By completing this tutorial, you will use the Nicks pallet to accomplish the fol
46
42
47
43
- See changes to the runtime by interacting with the new pallet using the front-end template.
48
44
49
-
## Add the Nicks pallet dependencies
45
+
## Add the Lottery pallet dependencies
50
46
51
47
Before you can use a new pallet, you must add some information about it to the configuration file that the compiler uses to build the runtime binary.
52
48
@@ -59,32 +55,32 @@ Because the Substrate runtime compiles to both a native platform binary that inc
59
55
For information about adding dependencies in `Cargo.toml` files, see [Dependencies](https://doc.rust-lang.org/cargo/guide/dependencies.html) in the Cargo documentation.
60
56
For information about enabling and managing features from dependent packages, see [Features](https://doc.rust-lang.org/cargo/reference/features.html) in the Cargo documentation.
61
57
62
-
To add the dependencies for the Nicks pallet to the runtime:
58
+
To add the dependencies for the Lottery pallet to the runtime:
63
59
64
60
1. Open a terminal shell and change to the root directory for the node template.
65
61
66
62
1. Open the `runtime/Cargo.toml` configuration file in a text editor.
67
63
68
64
1. Locate the [dependencies] section and note how other pallets are imported.
69
65
70
-
1. Copy an existing pallet dependency description and replace the pallet name with `pallet-nicks` to make the pallet available to the node template runtime.
66
+
1. Copy an existing pallet dependency description and replace the pallet name with `pallet-lottery` to make the pallet available to the node template runtime.
This line imports the `pallet-nicks` crate as a dependency and specifies the following:
74
+
This line imports the `pallet-lottery` crate as a dependency and specifies the following:
79
75
80
76
- Version to identify which version of the crate you want to import.
81
77
- The default behavior for including pallet features when compiling the runtime with the standard Rust libraries.
82
-
- Repository location for retrieving the `pallet-nicks` crate.
83
-
-Branch to use for retrieving the crate. Be sure to use the same **version** and **branch** information for the Nicks pallet as you see used for the other pallets included in the runtime.
78
+
- Repository location for retrieving the `pallet-lottery` crate.
79
+
-Tag to use for retrieving the crate. Be sure to use the same **version** and **tag** information for the Nicks pallet as you see used for the other pallets included in the runtime.
84
80
85
81
These details should be the same for every pallet in any given version of the node template.
86
82
87
-
1. Add the `pallet-nicks/std` features to the list of `features` to enable when compiling the runtime.
83
+
1. Add the `pallet-lottery/std` features to the list of `features` to enable when compiling the runtime.
88
84
89
85
```toml
90
86
[features]
@@ -93,7 +89,7 @@ To add the dependencies for the Nicks pallet to the runtime:
93
89
...
94
90
"pallet-aura/std",
95
91
"pallet-balances/std",
96
-
"pallet-nicks/std",
92
+
"pallet-lottery/std",
97
93
...
98
94
]
99
95
```
@@ -117,19 +113,25 @@ The `Config` trait is used to identify the parameters and types that the pallet
117
113
118
114
Most of the pallet-specific code required to add a pallet is implemented using the `Config` trait.
119
115
You can review what you to need to implement for any pallet by referring to its Rust documentation or the source code for the pallet.
120
-
For example, to see what you need to implement for the `nicks` pallet, you can refer to the Rust documentation for [`pallet_nicks::Config`](https://paritytech.github.io/substrate/master/pallet_nicks/pallet/trait.Config.html) or the trait definition in the [Nicks pallet source code](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/nicks/src/lib.rs).
116
+
For example, to see what you need to implement for the `Lottery` pallet, you can refer to the traitdefinition in the [Lottery pallet source code](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/lottery/src/lib.rs).
121
117
122
-
For this tutorial, you can see that the `Config` trait in the `nicks` pallet declares the following types:
118
+
For this tutorial, you can see that the `Config` trait in the `lottery` pallet declares the following types:
@@ -172,62 +174,72 @@ To review the `Config` trait for the Balances pallet:
172
174
As you can see in this example, the `impl pallet_balances::Config` block allows you to configure the types and parameters that are specified by the Balances pallet `Config` trait.
173
175
For example, this `impl` block configures the Balances pallet to use the `u128` type to track balances.
174
176
175
-
## Implement the configuration for Nicks
177
+
## Implement the configuration for Lottery
176
178
177
179
Now that you have seen an example of how the `Config` trait is implemented for the Balances pallet, you're ready to implement the `Config` trait for the Nicks pallet.
178
180
179
-
To implement the `nicks` pallet in your runtime:
181
+
To implement the `lottery` pallet in your runtime:
180
182
181
183
1. Open the `runtime/src/lib.rs` file in a text editor.
182
184
183
185
1. Locate the last line of the Balances code block.
184
186
185
-
1.Add the following code block for the Nicks pallet:
187
+
1.Before adding Lottery pallet's config, `pallet_random_collective_flip` is instantiated as `RandomnessCollectiveFlip`. For more information, you can see [Incorporate randomness](https://docs.substrate.io/reference/how-to-guides/pallet-design/incorporate-randomness/). Note that add `pallet_random_collective_flip` in `runtime/Cargo.toml` as above.
186
188
187
189
```rust
188
-
implpallet_nicks::ConfigforRuntime {
189
-
// The Balances pallet implements the ReservableCurrency trait.
190
-
// `Balances` is defined in `construct_runtime!` macro.
191
-
typeCurrency=Balances;
192
-
193
-
// Set ReservationFee to a value.
194
-
typeReservationFee=ConstU128<100>;
195
-
196
-
// No action is taken when deposits are forfeited.
197
-
typeSlashed= ();
198
-
199
-
// Configure the FRAME System Root origin as the Nick pallet admin.
@@ -248,7 +260,7 @@ To implement the `nicks` pallet in your runtime:
248
260
249
261
## Start the blockchain node
250
262
251
-
After your node compiles, you are ready to start the node that has been enhanced with nickname capabilities from the [Nicks pallet](https://paritytech.github.io/substrate/master/pallet_nicks/index.html) and interact with it using the front-end template.
263
+
After your node compiles, you are ready to start the node that has been enhanced with lanch a lottery from the [Lottery pallet](https://paritytech.github.io/polkadot-sdk/master/pallet_lottery/) and interact with it using the front-end template.
0 commit comments