Skip to content

Instantly share code, notes, and snippets.

View johnX9's full-sized avatar

John X johnX9

  • @infiniteXLabs
View GitHub Profile
// EOSLIB_SERIALIZE(struct_name, (property_1)(property_2)(property_3)...(property_n))
// typedef multi_index<N(table_name), object_template_to_use> multi_index_name;
typedef multi_index<N(player), player> playerIndex;
//@abi action
void add(const account_name account, string& username) {
/**
* We require that only the owner of an account can use this action
* or somebody with the account authorization
*/
require_auth(account);
/**
* We access the "player" table as creating an object of type "playerIndex"
//@abi action
void update(account_name account, uint64_t level, int64_t healthPoints, int64_t energyPoints) {
require_auth(account);
playerIndex players(_self, _self);
auto iterator = players.find(account);
eosio_assert(iterator != players.end(), "Address for account not found");
/**
//@abi action
void getplayer(const account_name account) {
playerIndex players(_self, _self);
auto iterator = players.find(account);
eosio_assert(iterator != players.end(), "Address for account not found");
/**
* The "get" function returns a constant reference to the object
* containing the specified secondary key
# cleos push action {account} {action} {data}
# account - The account providing the contract to execute
# action - The action to execute on the contract
# data - The arguments to the contract
cleos push action anorak getplayer '["anorak"]' -p anorak@active
executed transaction: 759ba984c4f9216d79fc473757a398ee6248c043ab6596cd8336a08512a4f465 104 bytes 2443 us
# anorak <= anorak::getplayer {"account":"anorak"}
>> Username: art3mis Level: 1 Health: 1000 Energy: 1000
# cleos set contract {account} {path_to_contract_folder} {path_to_.wast_file} {path_to_.abi_file}
cleos set contract anorak ./contracts/Players ./contracts/Players/Players.wast ./contracts/Players/Players.abi
Reading WAST/WASM from ./contracts/Players/Players.wast...
Assembling WASM...
Publishing contract...
executed transaction: 2187a85a5e80cbd2c0e6715b6847c95cbb5da5df7ed1171be87709507678795d 6472 bytes 6582 us
# eosio <= eosio::setcode {"account":"anorak","vmtype":0,"vmversion":0,"code":"0061736d010000000182011560037f7e7f0060057f7e7e7...
# eosio <= eosio::setabi {"account":"anorak","abi":"0e656f73696f3a3a6162692f312e300002046974656d0006076974656d5f69640675696e7...
eosiocpp -o Players.wast Players.cpp
eosiocpp -g Players.abi Players.cpp
# cleos push action {account} {action_name} '{data}' -p {account}@active
cleos push action anorak add '["anorak","art3mis"]' -p anorak@active
executed transaction: 00ea5aa48e50c33737b253ac24cb6bef3f296399e9a7e61b81044a852bb5c709 112 bytes 3015 us
# anorak <= anorak::add {"account":"anorak","username":"art3mis"}