Path: blob/main/docs/versioned_docs/version-v0.25/guide/04-nameservice/05-play.md
1721 views
------Play With Your Blockchain
If you haven't already, start a blockchain node in development:
The optional -r flag is useful in development mode since it resets the blockchain's state if it has been started before.
After the serve command has finished building the blockchain, a nameserviced binary is installed by default in the ~/go/bin directory.
The terminal window where the chain is started must remain open, so open a second terminal window to use nameserviced to run commands at the command line.
Buy a New Name
Purchase a new name using the buy-name command. The name is foo and the bid is 20token.
In the keeper for the buy name transaction, you added code to the msg_server_buy_name.go file that hard-coded the minimum bid to 10token. Any bid lower than that amount results in a rejected purchase.
where:
buy-name is the command that accepts two arguments
foo is the name
20token is the bid
the
--from aliceflag specifies the user account that signs and broadcasts the transaction
This buy-name command creates a transaction and prompts the user alice to sign and broadcast the transaction.
Here is what an unsigned transaction looks like:
Buy Name Transaction Details
Look at the transaction details:
The transaction contains only one message:
MsgBuyName.The message
@typematches the package name of the corresponding proto file,proto/nameservice/tx.proto.The
creatorfield is populated automatically with the address of the account broadcasting the transaction.The local account
aliceaddress iscosmos1p0f...km5d.Values of
nameandbidare passed as CLI arguments.
After the transaction is broadcast and included in a block, the blockchain returns a response where "code": 0 means the transaction was successfully processed.
Query the Chain for a List of Names
Query the chain for a list of name and corresponding values. Query commands don't need the --from flag, because they don't broadcast transactions and make only free requests.
The response confirms that the name foo was successfully purchased by alice and the current price is set to 20token.
Set a Value to the Name
Now that alice is an owner of the name, she can set the value to anything she wants. Use the set-name command to set the value to bar:
Query for a list of names again:
The response shows that name is now foo.
Buy an Existing Name
Use the bob account to purchase an existing name from alice. A successful bid requires that the buy price is higher than the current value of 20token.
In this buy-name command, the bid is updated to the latest bid of 40token and the --from bob flag specifies that the transaction is signed by the bob address.
Query for a list of names again:
The response shows a different creator address than alice (it's now the address for bob) and the price is now 40token.
Query the Bank Balance
Use the following command to see how the alice bank balance has changed after this transaction:
Test an Unauthorized Transaction
Try updating the value by broadcasting a transaction from the alice account:
An error occurs because alice sold the name in a previous transaction. The results show that alice is not the owner of the name and is therefore not authorized to change the value.
Conclusion
Congratulations 🎉. You have created the nameservice module and the nameservice application.
You successfully completed these steps:
Learned how to work with module dependencies
Use several scaffolding methods
Learned about Cosmos SDK types and functions
Used the CLI to broadcast transactions , and so much more
You are now prepared to continue your journey to learn about escrow accounts and IBC.