Nicks Module
Overview
Nicks is an example module for keeping track of account names on-chain. It makes no effort to create a name hierarchy, be a DNS replacement or provide reverse lookups. This module is only for demonstration purposes, so do not use this pallet as-is in production.
Module
First, we define the module inside the pallets/
folder as a ts
file. The path to the module should look similar to this:
Storage entries
Now we define storage entries inside nicks.ts
for our module like this:
Some interesting details:
NicksStorageEntries - a namespace where we define storage entries as functions. It's required to be a namespace and named accordingly:
moduleName + 'StorageEntries'
storage_map AccountId -
specifies the type of storage entry (Map) and type of argument it receives (AccountId)StorageEntry<T>
- An object that takes the type of value to be stored. And also module name and the entry name.
Constants
Sometimes your modules may require you to set constants that will be used inside the module. In Subsembly, constants are defined as a static function of a class, inside the assembly/runtime/runtime.ts
file like this:
Module Calls
And now we will define the core business logic of the module. It may include extrinsic calls that are exposed outside of the runtime and other internal function and constants. We define our Nicks module like this:
Here we have defined only one dispatchable call of our module. Note that, extrinsic call is a static function and returns array of bytes: code for the result of the extrinsic.
We define local error codes for the module as a static property
set_name
- Sets the provided name for the given originAccountId
Don't forget to include your new module for exports inside assembly/pallets/index.ts !
Last updated