Get Started with Substrate Names - RenegadeMinds/testbed GitHub Wiki

Get Started with Substrate Names

The Xaya Substrate Names pallet adds name functionality to Substrate-based blockchains.

This tutorial uses Ubuntu Linux.

Get Substrate Prerequisites

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

Get Xaya Substrate Names Pallet

Open a terminal and clone the Xaya Substrate Names pallet.

git clone https://github.com/xaya/substrate-names.git

Build and Start the Blockchain Node

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.

Blocks are produced

To reset the blockchain, use the purge-chain command as shown below.

target/release/node purge-chain --dev

Start the Front End

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/.

Substrate names web server

It will also open a browser window showing the front end.

Substrate names front end

Later you can start the front end without the yarn install command.

Test Name Operations

You can test name operations in the front end in your web browser.

Create or Update a Name

To create or update a name:

  1. Under Extrinsics, select name in the first drop down menu
  2. Select update in the second drop down menu
  3. In the first input, enter a name
  4. In the second input, enter a value for the name
  5. Click the Call button

Extrinsics > names > update

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

Transfer a Name to a New Owner

You can also transfer names to a new owner using their address.

  1. 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)
  2. At the top of the page, copy the address for "charlie"
  3. Under Extrinsics, select name in the first drop down menu
  4. Select transfer in the second drop down menu
  5. Enter the name you used above, e.g. "My name", into the first input
  6. Paste charlie's address into the second input
  7. Click the Call button

Extrinsics name transfer to charlie

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.

Create a Name with no Value

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.

More Information

For more information, see the README.md document in the Xaya substrate-names GitHub repository.

⚠️ **GitHub.com Fallback** ⚠️