Skip to content

Instantly share code, notes, and snippets.

View johnX9's full-sized avatar

John X johnX9

  • @infiniteXLabs
View GitHub Profile
void Marketplace::buy(account_name buyer, uint64_t productId) {
productIndex products(_self, _self);
auto iterator = products.find(productId);
eosio_assert(iterator != products.end(), "The product not found");
auto product = products.get(productId);
eosio_assert(product.quantity > 0, "The product is out of stock");
asset productPrice = asset(product.price, string_to_symbol(4, "OAS"));
# Create asset
# asset({amount}, string_to_symbol({precision}, {symbol}));
asset productPrice = asset(product.price, string_to_symbol(4, "OAS"));
# Do inline trasfer
# action({permission_level}, {contract_deployer}, {contract_action}, {data_to_pass}).send();
action(vector<permission_level>(), N(anorak), N(transfer), make_tuple(buyer, _self, productPrice, string(""))).send();
# Execute action from another contract
# action({permission_level}, {contract_deployer}, {contract_action}, {data_to_pass}).send();
# 1. Create new wallet with the name "oasis"
cleos wallet create -n oasis
# 2. Generate two pair of keys (use the command twice)
cleos create key
# 3. Import the generated private keys in the wallet(you need to specify the wallet at the end)
# {private_key_1} - This will be the OwnerKey
# {private_key_2} - This will be the ActiveKey
cleos wallet import --private-key={private_key_1} -n oasis
{
"account_name": "token",
"head_block_num": 70942,
"head_block_time": "2018-07-29T16:53:48.000",
"privileged": false,
"last_code_update": "1970-01-01T00:00:00.000",
"created": "2018-07-29T16:49:47.500",
"ram_quota": -1,
"net_weight": -1,
"cpu_weight": -1,
cleos create account eosio token {public-OwnerKey} {public-ActiveKey}
executed transaction: e0d7f17de1e7f1a7b73dfda511ce7714d25fceec6b43d86ddf997fb38852e0c2 200 bytes 2774 us
# eosio <= eosio::newaccount {"creator":"eosio","name":"token","owner":{"threshold":1,"keys":[{"key":"EOS6EhzztSvBp1K76GqF6A893bL...
cleos create key # OwnerKey
cleos create key # ActiveKey
cleos wallet import --private-key={eosio_account_private_key}
cleos wallet import --private-key={private-OwnerKey}
cleos wallet import --private-key={private-ActiveKey}
# Magic ball
cleos push action market add '{"account":"market","newProduct":{"product_id":1,"name":"magic ball","power":120,"health":10,"ability":"see the future","level_up":3,"quantity":10,"price":150}}' -p market@active
executed transaction: effdd4505745f336170dfdd1ab0e4579b7b578fada0273617de1c8204c042208 176 bytes 542 us
# market <= market::add {"account":"market","newProduct":{"product_id":1,"name":"magic ball","power":120,"health":10,"abilit...
cleos push action market getbyid '[1]' -p market
executed transaction: bd10a266a494919a578bc00cbaa73e0bbed52ad5d072fcca7b52d687c24e9367 104 bytes 618 us
# market <= market::getbyid {"productId":1}
>> Id: 1 | Name: magic ball | Power: 120 | Health: 10 | Ability: see the future | Level up: 3 | Quantity: 10 | Price: 150
//@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");
/**