Skip to content

First Steps

Ryan edited this page Mar 5, 2019 · 33 revisions

First Steps Tutorial

There are many tutorials and documents to help you get started, but let's get straight to some fast action by learning about XAYA and specifically xayad, the daemon engine at the core of the XAYA blockchain!

The XAYA blockchain is a decentralised data-store.

For minimal fees, people can create unique names (also called accounts) in the XAYA blockchain and update them with additional data (called values). The main attribute is that only the person who created a name has its private key to update this additional data. They cannot be stolen, forged or censored.

Values for names can be anything up to 2,048 bytes. For example, you could create a name called "Rita" and attach your email address to it. Then anyone who knows that you own "Rita" can see it on the XAYA blockchain and trust the value. In this case that is your email address, but you could store other data as well.

On XAYA these names are also known as accounts and the values (the data attached to the name) are moves in a game. Only the owner of the account can make moves from that account as they own the private key.

With just that above, it's possible to build decentralised games on XAYA.

For example, imagine Rita and Sue both have their own names (accounts) stored in the blockchain. They want to play a game of chess and they decide that Rita is white (starts first).

Rita can update the value of her account with the first move:

"e2 to e4"

After about 30 seconds this will enter the blockchain.

Now Sue (or anyone in the world) can read Rita's move in the XAYA blockchain and know it came from Rita. Sue would then update the value of her account with her own move. The game would continue back and forth until someone won.

This allows for a fully decentralised game of chess that anyone can verify and see who the winner is or if they tried an invalid move (tried to cheat).

While that example is very simple, it demonstrates the fundamentals of how games on XAYA work.

In this first steps tutorial we'll explain the steps to create your own unique secure name on the XAYA blockchain and update its value.

Get a Wallet

To interact with the XAYA blockchain you will need to run a XAYA wallet. There are multiple wallets but in this guide we will use xayad which is the headless daemon with an RPC interface.

If you haven't already, download one of the ZIP files then extract it.

Run the Daemon (xayad)

Open a command prompt or terminal and navigate to the wallet folder.

Run the following command:

xayad -rpcport=8396 -rpcuser=user -rpcpassword=password

The blockchain will begin synchronising (downloading) the blockchain. This can take some time and largely depends on your computer and network connection.

When xayad first runs it downloads all the blocks from peers until it catches up to the current block that everyone is on. If you stop the daemon and restart it, it will continue from where it left off. This could take some time depending on the speed of your computer, your internet connection, and your hard disk.

Open up another command prompt or terminal and navigate again to the xayad folder. You'll use this window to issue commands.

xaya-cli and curl

Now that we have the daemon running, we'll use the XAYA Command Line Interface (xaya-cli) or curl to issue commands. It's very easy and you'll learn along the way. For XAYA, you'll find that xaya-cli is far easier than curl. The xaya-cli program is included in the wallet download mentioned above.

However, there are many ways to interact with an RPC interface, and all of the ones that work for Bitcoin should also work for XAYA. Here's a link to some code examples.

Check the Network

Your first task is to check the network by confirming you are connected to other p2p xaya nodes. Here are the xaya-cli and curl commands:

xaya-cli -rpcuser=user -rpcpassword=password getnetworkinfo

Or with curl:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnetworkinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

NOTE: With both xaya-cli and curl you will need to ensure that you've properly escaped anything that requires it. Also, mind which quotes you use (' vs "), depending on your platform.

Those commands will return something similar to this:

{
	"version": 1019900,
	"subversion": "/Xaya:1.1.99/",
	"protocolversion": 110015,
	"localservices": "000000000000040d",
	"localrelay": true,
	"timeoffset": 1,
	"networkactive": true,
	"connections": 8,
	"networks": [
		{
		"name": "ipv4",
		"limited": false,
		"reachable": true,
		"proxy": "",
		"proxy_randomize_credentials": false
		},
		{
		"name": "ipv6",
		"limited": false,
		"reachable": true,
		"proxy": "",
		"proxy_randomize_credentials": false
		},
		{
		"name": "onion",
		"limited": true,
		"reachable": false,
		"proxy": "",
		"proxy_randomize_credentials": false
		}
	],
	"relayfee": 0.00100000,
	"incrementalfee": 0.00001000,
	"localaddresses": [
	],
}

From here we can see that we are connected to 8 nodes. Which is the set maximum number of outgoing connections in the client. It's possible to open ports on your system to receive incoming connections, but this is not required. You can ignore the other information in there for this tutorial.

If you don't have any connections then you may need to wait a few minutes or you may have some networking issues on your computer, so you should sort that out before continuing.

Check Synchronisation

Next, lets check how far we are with syncing. Type in the following command.

xaya-cli -rpcuser=user -rpcpassword=password getblockchaininfo

Or with curl:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

You'll get a result similar to this:

{
	"chain": "main",
	"blocks": 598466,
	"headers": 598466,
	"bestblockhash": "4ff74462ecde7624ed069687954da31cec2c3fc3328a669b7a62511a5ad7753d",
	"mediantime": 1550319823,
	"verificationprogress": 0.9999955845690718,
	"initialblockdownload": false,
	"chainwork": "0000000000000000000000000000000000000000001a29ea874e394c2041f282",
	"size_on_disk": 567360856,
	"pruned": false,
	"softforks": [
		{
		"id": "bip34",
		"version": 2,
		"reject": {
			"status": true
			}
		},
		{
		"id": "bip66",
		"version": 3,
		"reject": {
			"status": true
			}
		},
		{
		"id": "bip65",
		"version": 4,
		"reject": {
			"status": true
			}
		}
	],
	"bip9_softforks": {
	},
}

The value for blocks is the current block your client is synced with. The headers value is the current block number of the headers downloaded. Generally if you are still syncing, headers is greater than blocks. Once you are fully synced, blocks = headers.

You can check if you are fully synced by checking the block explorer, which should be on the latest block.

On Linux you can use the following command to see the blocks come in in real time.

watch xaya-cli -rpcuser=user -rpcpassword=password getblockchaininfo

CHI Powers the XAYA Blockchain

CHI is the native cryptocurrency for the XAYA blockchain. It powers transactions. Operations such as updating a name (see below) require tiny amounts of CHI. That small amount of CHI is a fee charged by miners who secure the blockchain.

Get a CHI Address

You'll need some CHI for some commands, but you'll need a CHI address first. CHI addresses are used to send and receive coins. Let's get you a CHI address. Issue the following command. You can change the label for the address, "This is my new address!", to anything you like.

xaya-cli -rpcuser=user -rpcpassword=password getnewaddress "This is my new address!"

Or with curl:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

The daemon will return a single CHI address. It will look similar to the following.

CSdTuozaJbMsEjha54AbN6AFHSn4uT9nMX

Copy and save the address that the daemon returned. You can use it to receive CHI now. (Do not use the example address above.)

Get Some CHI

Our examples use mainnet, which requires real CHI. For this tutorial you'll need less than 0.1 CHI. Developers can ask for that CHI in our Forums, Telegram, or other channels. You need only provide us with a valid CHI address.

However, you can also do this on testnet or regtestnet for free. See Getting Started with Regtestnet for more information about that.

Get a Balance

Now that you have some CHI, let's check your balance. Try out the following command.

xaya-cli -rpcuser=user -rpcpassword=password getbalance

Your balance will be returned similar to this:

1.23456789

What is a XAYA Name?

Before we create a name, it would be useful to know what a name is. The short answer is that it's a unique ID that only the owner can control. Let's find out what that means.

From the XAYA Specifications blockchain document:

Name and Value Restrictions

Valid names and values in Xaya must satisfy additional constraints compared to Namecoin, which only enforces maximum lengths. In particular, these conditions must be met by names and values:

  • Names can be up to 256 bytes long and values up to 2,048 bytes.
  • Names must have a namespace. This means that they must start with one or more lower-case letters and /. Expressed as a regexp, this means they must match: [a-z]+\/.*
  • Names must be valid UTF-8 and must not contain unprintable ASCII characters, i.e. those with a value less than 0x20.
  • Values must be valid JSON and parse to a JSON object.

If you own a name, you can update its value. This functions as a key/value pair, where the name is the key. The value can be used inside of games, for ID purposes, among other things as well.

The p/ namespace is used for game accounts, i.e. "p" is for "player".

The g/ namespace is used for game accounts, i.e. "g" is for "game".

Some examples of valid names include:

  • p/Rita
  • p/Sue
  • g/helloworld
  • g/mv

Create a XAYA Name

Names are the core of XAYA. Only YOU can control your name and do moves in games. Creating names is very easy.

In your command prompt, issue a command like this where "<my name>" is your chosen name:

xaya-cli -rpcuser=user -rpcpassword=password name_register "p/<my name>" "{}"

Or with curl:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "name_register", "params": [{"p/<my name>"}] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

You should receive a response as a transaction ID, which is a long hexadecimal value, e.g.:

28d489d22ec3908978ce678746ad270a60254d8edd4a978d286d1251ebfb8043

If it fails, most likely you've tried to get a name that is already reserved. Check the error message and try again.

Congratulations! You've immortalised yourself on the XAYA blockchain!

Is Your Name in the Blockchain Yet?

Now that you have your first name, let's see if it's in the blockchain. Try the following command:

xaya-cli name_pending "p/<my name>"

Or with curl:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "name_pending", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

If it returns a result, your name hasn't been mined into the blockchain yet. Wait a minute then try again.

Find All Your Names

You can find all the names you own in your wallet. Try the following command:

xaya-cli name_list

Or with curl:

curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "name_list", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

That returns a list of all your names.

Update the Value for Your Name

Now that you have a name, it's time to say hello! by updating it's value (aka submitting a move)

Try running the following command with the name you registered above.

xaya-cli -rpcuser=user -rpcpassword=password name_update "p/<my name>" "{\"g\":{\"helloworld\":{\"m\":\"Hello everybody!\"}}}"

Or with curl:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "name_update", "params": ["p/<my name>", "new-value"] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

Congratulations! You just made a move in the "Hello World!" game! In a later tutorial you'll be able to see your move along with everyone else's moves and we'll explain the JSON object that is required for values on the chain.

Note how the value is escaped with back slashes.

View your name in the Blockchain

Now you or anyone in the world can lookup your name on the xaya blockchain. Try running the following command with your name.

xaya-cli -rpcuser=user -rpcpassword=password name_show "p/<my name>"

Or with curl:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "name_show", "params": ["p/<my name>"] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/

you should see some information about your name along with the value you set for it.

Congratulations! You've completed your first steps.

Clone this wiki locally