EOS-game tutorial

THE GAME
Elementals Battles is a single player card game set in a fantasy world where you, the player, harness the power of Wood, Fire, and Water to dominate your opponent! The game is played against a smart-contract based AI, and is deployed on a live EOSIO blockchain.

The versions that we used for this tutorial are:

Docker version 17.06 or newer
EOSIO version 1.2.5
eosjs version 20.0.0-beta1

The quickest way to set up a development environment is to use a prebuilt and prepackaged Docker image which can be obtained from: https://hub.docker.com/r/eosio/eos-dev/

Pull the docker image

docker pull eosio/eos-dev:v1.2.5

Create Network

Here we’ll use docker’s network command to create a network for nodeos and keosd to share.

docker network create eosdev

Boot Containers

Nodeos (Core Daemon)

docker run --name nodeos -d -p 8888:8888 --network eosdev \
-v /tmp/eosio/work:/work -v /tmp/eosio/data:/mnt/dev/data \
-v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev \
/bin/bash -c "nodeos -e -p eosio --plugin eosio::producer_plugin \
--plugin eosio::history_plugin --plugin eosio::chain_api_plugin \
--plugin eosio::history_api_plugin \
--plugin eosio::http_plugin -d /mnt/dev/data \
--config-dir /mnt/dev/config \
--http-server-address=0.0.0.0:8888 \
--access-control-allow-origin=* --contracts-console --http-validate-host=false"

These settings accomplish the following:

  1. Forward port 8888
  2. Connect to eosdev local network you created in previous step
  3. Alias three volumes on your local drive to the docker container.
  4. Run the Nodeos startup in bash. This command loads all the basic plugins, set the server address, enable CORS and add some contract debugging.
  5. Mount some directories in /tmp on local machine, changes to these folders will persist in docker container. (for example, you’ll want to place contracts in /tmp/eosio/work so you can upload contracts to your node.

Run Keosd (Wallet and Keystore)

docker run -d --name keosd --network=eosdev \
-i eosio/eos-dev /bin/bash -c "keosd --http-server-address=0.0.0.0:9876"

Check your installation

Check that Nodeos is Producing Blocks

docker logs --tail 10 nodeos

Check the Wallet

docker exec -it keosd bash
cleos --wallet-url http://127.0.0.1:9876 wallet list keys

Check Nodeos endpoints

This will check that the RPC API is working correctly, pick one.

curl http://localhost:8888/v1/chain/get_info

Alias Cleos

Firstly, we need to find the IP address of keosd, by the following:

docker network inspect eosdev

Substitute the keosd IPv4Address found on your own machine for 172.18.0.3 in the example above.

alias cleos='docker exec -it nodeos /opt/eosio/bin/cleos --url http://127.0.0.1:8888 --wallet-url http://172.18.0.3:9876'

What this does is create an alias to cleos on your local system, and links that alias to a command that is executed inside the nodeos container. This is why the –url parameter is referencing localhost on port 8888, while the –wallet-url references keosd

build smart contract

eosiocpp -o destination.wasm source.cpp
eosiocpp -g destination.abi source.cpp

//upload contract
cleos set contract account_name ../contract_dir -p account_name@active

push contract

cleos push action contract_name action_name '["action_parameter"]' -p authorizer_account