Get Started with Substrate Names - RenegadeMinds/testbed GitHub Wiki
The Xaya Substrate Names pallet adds name functionality to Substrate-based blockchains.
This tutorial uses Ubuntu Linux.
You must first get the Substrate prerequisites. To do that, follow the Substrate "Set Up Your Computer" tutorial.
In short, run the following commands to setup your compter:
sudo apt-get install curl
curl https://getsubstrate.io -sSf | bash -s -- --fast
source $HOME/.cargo/env
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
rustup update nightly
rustup update stable
rustup target add wasm32-unknown-unknown --toolchain nightly
Open a terminal and clone the Xaya Substrate Names pallet.
git clone https://github.com/xaya/substrate-names.git
Next, build and start the blockchain node.
cd substrate-names/node
cargo build --release
target/release/node --dev
The terminal will begin displaying blocks being produced.
To reset the blockchain, use the purge-chain
command as shown below.
target/release/node purge-chain --dev
Next, open up a new terminal and start the front end.
cd substrate-names/frontend
yarn install
yarn start
This will start a local webserver on http://localhost:8000/.
It will also open a browser window showing the front end.
Later you can start the front end without the yarn install
command.
You can test name operations in the front end in your web browser.
To create or update a name:
- Under Extrinsics, select
name
in the first drop down menu - Select
update
in the second drop down menu - In the first input, enter a name
- In the second input, enter a value for the name
- Click the Call button
You'll see some output in the Events panel to the right of the Extrinsics section.
X Blocks Ago
names:NameUpdated:: (phase={"ApplyExtrinsic":1})-1
Name: 0x4d79206e616d65, NameData: {"value":"0x536f6d652076616c7565","owner":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY","expiration":null}
Event when a name is updated (or created).
X Blocks Ago
names:NameRegistered:: (phase={"ApplyExtrinsic":1})-0
Name: 0x4d79206e616d65
Event when a name is newly created.
The name and value are hex encoded. 0x4d79206e616d65
is "My name" and 0x536f6d652076616c7565
is "Some value".
If you try to create a name that already exists, or update a name that you do not own, you will receive an error message in the Events panel similar to as follows:
X Blocks Ago
system:ExtrinsicFailed:: (phase={"ApplyExtrinsic":1})-21
DispatchError: Other, DispatchInfo: {"weight":10000,"class":"normal","paysFee":true}
An extrinsic failed.
Make sure that you have the proper account selected in the account selector drop down menu in the upper-right corner of the page.
If you do not have enough coins, you may receive an error message below the call button:
:( transaction failed
You can also transfer names to a new owner using their address.
- Ensure that the ALICE account is selected in the account selector drop down menu in the upper-right corner of the page (or whichever account you used in "Create or Update a Name" above)
- At the top of the page, copy the address for "charlie"
- Under Extrinsics, select
name
in the first drop down menu - Select
transfer
in the second drop down menu - Enter the name you used above, e.g. "My name", into the first input
- Paste charlie's address into the second input
- Click the Call button
The Events panel will update with the new event similar to as shown below.
X Blocks Ago
names:NameUpdated:: (phase={"ApplyExtrinsic":1})-4
Name: 0x4d79206e616d65, NameData: {"value":"0x536f6d652076616c7565","owner":"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y","expiration":null}
Event when a name is updated (or created).
You can see in the NameData
JSON that the name "My name" (encoded in hex) has a new owner, i.e. the address that you copied from charlie.
When you create a name using the update
function, the value (input number 2) field is mandatory and cannot be empty.
If you wish to create a name with no initial value attached to it, you must instead use the transfer
function. You can use the address for the same account when you do this. The Events panel will update similar to as follows:
X Blocks Ago
names:NameUpdated:: (phase={"ApplyExtrinsic":1})-26
Name: 0x4d7920666f75727468206e616d65, NameData: {"value":"0x","owner":"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY","expiration":null}
Event when a name is updated (or created).
Note that the value field in the JSON is "0x", so the value is empty.
For more information, see the README.md document in the Xaya substrate-names GitHub repository.