Quick Start - RenegadeMinds/testbed GitHub Wiki
The basics you should know about games on xaya.
They are generally made up of 3 parts.
The XAYA blockchain is a decentralised data store.
For a small fee (that goes to miners who secure the chain) It allows you to create and store “names or words or any string of characters” in the blockchain that are unique.
You are then able to change the values of those names (add additional data). Only you can as you own the private key. For example, you could create the name “Ryan” in the blockchain and then add some values to it at any point in time such as
“email = [email protected].”
Anybody in the world who knows you own the name Ryan, knows that only you could have put that email address, so it’s probably right. And no one could steal or forge your xaya identity. There are many other use cases but we’ll leave it at that for now.
Generally we also call these names in Xaya - “accounts”. But you may hear us call them Names too.
With just the daemon, you could build games on XAYA with just that (but there is more to it that will be explained later)
Example game:
So, you can create an account called Ryan and instead of giving it values such as an email address you can give it moves or actions for in a game.
For example, if you create a name “Ryan” and I created a name “Andy” we could have a game of chess.
I could update my name with my move first, like king's pawn e2 to e4.
Then you could send yours by updating your name with the values of your move.
As the blocks come in one after another (every 30 seconds with the updates) we can have a decentralised game of chess.
You can also prove who is the winner by showing someone the moves and as only the person who owns the name (account) can make the moves, you can prove nobody cheated or nobody faked that persons identity.
There is of course a lot more to XAYA that this (you need to be able to extract the updates every block for example), but this is the basic concept of how it all works.
For it to be more automated and more fun, you’d also want an app and front end that shows the peices on the board, tell you if a move is invalid and maybe even tell you if it’s checkmate, and you can do that. In the example of chess above though you’d have to probably do it on paper or a chess board or use some manual chess app where you place the pieces for both players. Like if you played chess over email.
In any case, before we go to deep in the other parts of xaya. Lets first
- Configure and run a XAYA wallet a. Run xayad correctly b. Check if you are connected to other peers c. Check if you are syncing or synced
- Get some CHI
- Create a name in the XAYA blockchain
- Update the name “Hello World”
- Check the current value of a name/account in the blockchain
To do anything in a decentralised trustless way on XAYA you need the xaya wallet.
The headless daemon is called xayad and there is also a QT GUI version, xaya-qt. We also provide XAYA Electron which is written in angular electron? And accesses xayad through it’s rpc.
For the purpose of this basic guide we will use xayad. Download it here or you can build it from source here.
XAYAd has an rpc interface (HTTP JSON-RPC). We will execute xayad with the following options (which should be self explanatory).
-rpcport=18396
-rpcuser=user
-rpcpassword=password
Giving us the command:
xayad -rpcport=8396 -rpcuser=user -rpcpassword=password
You should now see your screen scrolling with information as the “daemon” (xayad) initializes. It should also start synchronizing blocks.
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 say the next day, it will catch up from where it left off. This could take some time depending on the speed of your computer, your internet and your hard disk.
While it is syncing or after, lets check some things with the xaya RPC.
There are numerous ways to interact with the RPC interface, but in this example we will use xaya-cli. It is a simple to use tool that formats all commands simply and easily.
We’ll also show some examples in curl as well.
xaya-cli is included in the binary downloads as linked above or if you built from source it is in the src directory.
As our first command, lets first see if we have any peers and how many we are connected to (a peer is another xaya blockchain node).
xaya-cli:
xaya-cli getnetworkinfo
curl:
curl --user user --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnetworkinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:8396/
Note that with curl you will need to make sure it is escaped properly.
{
"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 information in there at this stage.
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.
Next, lets check how far we are with syncing. Issue this command:
xaya-cli getblockchaininfo
{
"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 could check if you are fully synced by checking the block explorer which “should” be on the latest block.
You could (on Linux) if you want to see the blocks come in:
watch Xaya-cli getblockchaininfo
Whether you are sync’d or not, you’ll need some CHI (the cryptocurrency that powers the XAYA blockchain). Generally in a testing environment you would use either testnet or regtest. In testnet you can quite easily mine yourself some coins (without expensive hardware) and in regtest mode you can mine instantly with 1 command.
This guide uses mainnet (the main or "real" network) to avoid any confusion later. However, once you've finished this tutorial you should use testnet or regtest for game development.
The first thing you need to do is generate an address.
xaya-cli getnewaddress
This will return a CHI address such as CN8Jp3a32XLgKdDpKKtfxeSr3ZRsq2wsX6.
You now need some CHI. For development, anybody on the forum, or in telegram or via our support email will send you some CHI. You need less than 0.1 CHI to finish this tutorial. Just send them your address.
Once someone has confirmed they have sent you some CHI, you can check with the following command.
xaya-cli getbalance
It will return your balance, e.g. 0.10000000. (CHI has 8 decimal places.)
If it shows 0, wait a minute or 2 to make sure it goes into the chain, or check the block explorer and search for your address.
Before we create a name (account) in the XAYA blockchain, we must first explain namespaces.
As a sort of “standard” that everyone should follow (and for some later applications in the turorial to work), you should prefix the “namespace” for your name. XAYA games use 2 fixed namespaces.
- p/: This is for players/accounts/names
- g/: This is for games and is used for some later tools that we provide.
For your name/account, you must add p/
in front as shown below.
p/snailbrain
The command to create a unique name on the blockchain is name_register.
Run this command below to register your name (replacing with your chosen name). The command expects valid JSON after the name. In this example we use "{}" for a blank value that is valid.
xaya-cli name_register "p/<yourname>" "{}"
The following command would register "andy" in the "p/" namespace.
xaya-cli name_register "p/andy" "{}"
If the command succeeds, it will return a transaction ID, which is a hexadecimal value.
1a2e044e8f6b24da04852859a9c08a607c4d9bda7a2d92a0199722d5198e397e
If it fails, it will return an error, such as the name is already taken or you have no CHI, etc.
You’ll now need to wait for the transaction to get “mined” into the next block. This should generally be less than 1 minute. On average, it's 30 seconds.
You can check if your name_register command has gotten into the blockchain by issuing the following command.
xaya-cli name_list
This will list all the names that you own. If this is your first time creating a name in your wallet, it will show the new one you have created along with some other information. If it doesn't, you can issue the command shown below to check if the transaction (name_register) is still waiting to be mined.
xaya-cli name_pending p/<yourname>
If it returns anything, then you need to wait a little longer.
Congratulations! You've just immortalised yourself in the XAYA blockchain! :)
As explained earlier, name values can be used for game moves or storing other data, like email addresses or whatever you like.
To update a name you use the name_update
RPC.
Let's update your name's value to “Hello World!”.
xaya-cli name_update {"m":"Hello World!"}
And that’s it. Congratulations!
You or anyone in thr world can now look you up on the xaya blockchain with the following command.
xaya-cli name_show "p/<yourname>"
Try it yourself. You should see your name's value.
This is the basis of how all games work on xaya, only instead of a message or an email address, you add your game moves, such as a waypoint, an action, or selling an item in a game world.
Your game just needs to process all the moves in each block to compute the state of the game. Does that sound easy or what?
Next, go on to the next tutorial. It is more advanced and provides a way of doing just that.
To learn more about RPCs- go here to xaya_tutorials To learn more about blah go here Daniel’s Specs To learn more about wahh go hear
Congrats on step 1 of 93