Skip to content

Commit 261bed0

Browse files
Zihan ZhaoZihan Zhao
Zihan Zhao
authored and
Zihan Zhao
committed
rewrite add a pallet to the runtime done
1 parent 1d4429e commit 261bed0

File tree

12 files changed

+20
-14724
lines changed

12 files changed

+20
-14724
lines changed

content/md/en/docs/tutorials/build-application-logic/add-a-pallet.md

+20-41
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ To start the local Substrate node:
286286

287287
## Start the front-end template
288288

289-
Now that you have added a new pallet to your runtime, you can use the [Substrate front-end template](/tutorials/build-a-blockchain/build-local-blockchain/#install-the-front-end-template) to interact with the node template and access the Nicks pallet.
289+
Now that you have added a new pallet to your runtime, you can use the [Substrate front-end template](/tutorials/build-a-blockchain/build-local-blockchain/#install-the-front-end-template) or [Polkadot/Substrate Portal](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944) (used in this tutorial) to interact with the node template and access the Lottery pallet.
290290

291291
To start the front-end template:
292292

@@ -302,62 +302,41 @@ To start the front-end template:
302302

303303
1. Open `http://localhost:8000/` in a browser to view the front-end template.
304304

305-
## Set a nickname using the Nicks pallet
305+
## Launch a lottery using the Lottery pallet
306306

307-
After you start the front-end template, you can use it to interact with the Nicks pallet you just added to the runtime.
307+
After you start the front-end template, you can use it to interact with the Lottery pallet you just added to the runtime.
308308

309-
To set a nickname for an account:
309+
To set startLottery's parameters:
310310

311-
1. Check the account selection list to verify that the Alice account is currently selected.
311+
1. According to our configuration, we need to have administrative privileges. In the `Developer` menu, verify that **Sudo** is selected.
312312

313-
1. In the Pallet Interactor component, verify that **Extrinsic** is selected.
313+
2. Select **lottery** from the list of pallets available to call.
314314

315-
2. Select **nicks** from the list of pallets available to call.
315+
3. Select **startLottery** as the function to call from the lottery pallet.
316316

317-
3. Select [**setName**](https://paritytech.github.io/substrate/master/pallet_nicks/pallet/enum.Call.html#variant.set_name) as the function to call from the nicks pallet.
317+
4. Set up a new lottery by filling up the 4 parameters:
318318

319-
4. Type a **name** that is longer than the `MinNickLength` (8 characters) and no longer than the `MaxNickLength` (32 characters).
319+
- `price`: The cost of a single ticket.
320+
- `length`: How long the lottery should run for starting at the current block.
321+
- `delay`: How long after the lottery end we should wait before picking a winner.
322+
- `repeat`: If the lottery should repeat when completed.
320323

321-
![Select the pallet and the function to call](/media/images/docs/tutorials/add-a-pallet/set-name-function.png)
324+
![Select the pallet and the function to call](/media/images/docs/tutorials/add-a-pallet/start-lottery-function.png)
322325

323-
5. Click **Signed** to execute the function.
326+
5. Click **Submit Sudo** to execute the function.
324327

325-
6. Observe the status of the call change from Ready to InBlock to Finalized and the note the [events](https://paritytech.github.io/substrate/master/pallet_nicks/pallet/enum.Event.html) emitted by the Nicks pallet.
328+
6. Observe the status of the call change from Ready to InBlock to Finalized and the note the events emitted by the Lottery pallet.
326329

327-
![Successful update to the nickname for Alice](/media/images/docs/tutorials/add-a-pallet/set-name-result.png)
328-
329-
## Query information for an account using the Nicks pallet
330-
331-
Next, you can use Query capability to read the value of Alice's nickname from the runtime storage for the Nicks pallet.
332-
333-
To return the information stored for Alice:
334-
335-
1. In the Pallet Interactor component, select **Query** as the Interaction Type.
336-
337-
1. Select **nicks** from the list of pallets available to query.
338-
339-
1. Select [**nameOf**](https://paritytech.github.io/substrate/master/pallet_nicks/pallet/enum.Call.html#variant.set_name) as the function to call.
340-
341-
1. Copy and paste the address for the **alice** account in the AccountId field, then click **Query**.
342-
343-
![Read a name](/media/images/docs/tutorials/add-a-pallet/Alice-query-result.png)
344-
345-
The return type is a tuple that contains two values:
346-
347-
- The hex-encoded nickname for the Alice account `53756273747261746520737570657273746172202d20416c696365`.
348-
If you convert the hex-encoded value to a string, you'll see the name you specified for the `setName` function.
349-
- The amount that was reserved from Alice's account to secure the nickname (`100`).
350-
351-
If you were to query the Nicks pallet for the `nameOf` for Bob's account, you would see the value `None` returned because Bob has not invoked the `setName` function to reserve a nickname.
330+
![Successfully select winner](/media/images/docs/tutorials/add-a-pallet/start-lottery-result.png)
352331

353332
## Explore additional functions
354333

355334
This tutorial illustrates how to add a simple pallet to the runtime and demonstrates how to interact with the new pallet using the predefined front-end template.
356-
In this case, you added the `nicks` pallet to the runtime and called the `set_name` and `nameOf` functions using the front-end template.
357-
The `nicks` pallet also provides two additional functions—the `clear_name` function and the `kill_name` function—that enable an account owner to remove the reserved name or a root-level user to forcibly remove an account name.
358-
You can learn about additional features—such as the use of the Sudo pallet and origin accounts—by exploring how these functions work.
335+
In this case, you added the `lottery` pallet to the runtime and called the `start_lottery` functions using the front-end template.
336+
The `lottery` pallet also provides other functions like the `stop_repeat` function.
337+
You can learn about additional features—such as giving Alice account the Sudo privileges.
359338
However, these features are beyond the intended scope of this tutorial.
360-
If you want to explore additional features exposed through the Nicks and Sudo pallets, see [Next steps](#next-steps) and select [Specify the origin for a call](/tutorials/build-application-logic/specify-the-origin-for-a-call).
339+
If you want to explore additional features exposed through the Lottery and Sudo pallets, see [Next steps](#next-steps) and select [Specify the origin for a call](/tutorials/build-application-logic/specify-the-origin-for-a-call).
361340

362341
## Next steps
363342

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)