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 \ |
These settings accomplish the following:
- Forward port 8888
- Connect to eosdev local network you created in previous step
- Alias three volumes on your local drive to the docker container.
- Run the Nodeos startup in bash. This command loads all the basic plugins, set the server address, enable CORS and add some contract debugging.
- 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 \ |
Check your installation
Check that Nodeos is Producing Blocks
docker logs --tail 10 nodeos |
Check the Wallet
docker exec -it keosd bash |
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 |
push contract
cleos push action contract_name action_name '["action_parameter"]' -p authorizer_account |