# Build and run the app

# Building the nameservice application

This repo contains a complete nameservice application. If you want to build this completed version Go 1.13.0+ is required.

Add some parameters to environment is necessary if you have never used the go mod before.

Copymkdir -p $HOME/go/bin echo "export GOBIN=\$GOPATH/bin" >> ~/.bash_profile echo "export PATH=\$PATH:\$GOBIN" >> ~/.bash_profile source ~/.bash_profile Expand

Now, you can install and run the application.

If you have not completed the tutorial then you can follow the below cloning instructions:

Copy# Clone the source of the tutorial repository git clone https://github.com/cosmos/sdk-tutorials.git cd sdk-tutorials cd namerservice ExpandCopy# Install the app into your $GOBIN make install # Now you should be able to run the following commands: nsd help nscli help Expand

# Running the live network and using the commands

To initialize configuration and a genesis.json file for your application and an account for the transactions, start by running:

NOTE: In the below commands addresses are pulled using terminal utilities. You can also just input the raw strings saved from creating keys, shown below. The commands require jq to be installed on your machine.

NOTE: If you have run the tutorial before, you can start from scratch with a nsd unsafe-reset-all or by deleting both of the home folders rm -rf ~/.nscli ~/.nsd

NOTE: If you have the Cosmos app for ledger and you want to use it, when you create the key with nscli keys add jack just add --ledger at the end. That's all you need. When you sign, jack will be recognized as a Ledger key and will require a device.

Copy# Initialize configuration files and genesis file # moniker is the name of your node nsd init --chain-id namechain # Copy the `Address` output here and save it for later use # [optional] add "--ledger" at the end to use a Ledger Nano S nscli keys add jack # Copy the `Address` output here and save it for later use nscli keys add alice # Add both accounts, with coins to the genesis file nsd add-genesis-account $(nscli keys show jack -a) 1000nametoken,100000000stake nsd add-genesis-account $(nscli keys show alice -a) 1000nametoken,100000000stake # Configure your CLI to eliminate need for chain-id flag nscli config chain-id namechain nscli config output json nscli config indent true nscli config trust-node true nsd gentx --name jack Expand

After you have generated a genesis transaction, you will have to input the genTx into the genesis file, so that your nameservice chain is aware of the validators. To do so, run:

nsd collect-gentxs

and to make sure your genesis file is correct, run:

nsd validate-genesis

You can now start nsd by calling nsd start. You will see logs begin streaming that represent blocks being produced, this will take a couple of seconds.

You have run your first node successfully.

Copy# First check the accounts to ensure they have funds nscli query account $(nscli keys show jack -a) nscli query account $(nscli keys show alice -a) # Buy your first name using your coins from the genesis file nscli tx nameservice buy-name jack.id 5nametoken --from jack # Set the value for the name you just bought nscli tx nameservice set-name jack.id 8.8.8.8 --from jack # Try out a resolve query against the name you registered nscli query nameservice resolve jack.id # > 8.8.8.8 # Try out a whois query against the name you just registered nscli query nameservice whois jack.id # > {"value":"8.8.8.8","owner":"cosmos1l7k5tdt2qam0zecxrx78yuw447ga54dsmtpk2s","price":[{"denom":"nametoken","amount":"5"}]} # Alice buys name from jack nscli tx nameservice buy-name jack.id 10nametoken --from alice # Alice decides to delete the name she just bought from jack nscli tx nameservice delete-name jack.id --from alice # Try out a whois query against the name you just deleted nscli query nameservice whois jack.id # > {"value":"","owner":"","price":[{"denom":"nametoken","amount":"1"}]} Expand

# Run second node on another machine (Optional)

Open terminal to run commands against that just created to install nsd and nscli

# init use another moniker and same namechain

Copynsd init --chain-id namechain Expand

# overwrite ~/.nsd/config/genesis.json with first node's genesis.json

# change persistent_peers

Copyvim /.nsd/config/config.toml persistent_peers = "id@first_node_ip:26656" run "nscli status" on first node to get id. Expand

# start this second node

Copynsd start Expand

# Congratulations, you have built a Cosmos SDK application! This tutorial is now complete. If you want to see how to run the same commands using the REST server you'll need to run the REST server.