"Could you share different types of dapp transaction examples explaining..."
HIVE
PVE: PVP: TRADING for our Hive-Engine token DOOM:WAX
PVE: crypto4shots: it sends to players only our Wax token BOOMPVP: crypto1shots (added this address in DappRadar and awaiting approval) → it send to players WAX transfers, WAX token BOOM and Sponsored Wax tokens (vary)TRADING:HIVE
PVE: any Hive playerPVP: any Hive playerTRADING: any Hive userWAX
PVE: any Wax playerPVP: any Wax playerTRADING: any Wax userIt’s sent from the sender to the receiver.
If that’s what you need, to know the value of the token at the time of the transfer, I quickly put together these scripts and they work as expected to fetch the current $ value of our tokens:
HIVE:
var getHiveEngineTokenPrice = async ({ tokenName }) => {
const tokenInfoUrl = `https://api.hive-engine.com/rpc/contracts`;
const tokenInfoBody = {
"jsonrpc":"2.0",
"method":"find",
"params": {
"contract":"market",
"table":"metrics",
"query":{ "symbol": tokenName },
"limit": 1,
"offset": 0,
"indexes":[]
},
"id":1
};
const tokenInfoResponse = await fetch(tokenInfoUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(tokenInfoBody),
});
const tokenInfoData = await tokenInfoResponse.json();
const lastPrice = tokenInfoData.result[0].lastPrice;
console.log(`$${tokenName} current price on Hive-Engine: ${lastPrice} HIVE`);
const hivePriceUrl = `https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd`;
fetch(hivePriceUrl)
.then(response => response.json())
.then(data => {
const priceUSD = data.hive.usd;
console.log(`HIVE current price is $${priceUSD}`);
const tokenPriceUSD = lastPrice * priceUSD;
console.log(`The current price of $${tokenName} in USD is $${tokenPriceUSD.toFixed(4)}.`);
});
};
var tokenName = 'DOOM';
getHiveEngineTokenPrice({ tokenName });
WAX:
var getFungibleTokenPrice = async ({ tokenPair }) => {
const { tokenName, cryptoName, marketNumber } = tokenPair;
const cryptoNameLc = cryptoName.toLowerCase();
const data = await fetch(`https://wax.alcor.exchange/api/markets/${marketNumber}/deals`).then(res => res.json());
const lastTransactionPrice = data[0].unit_price;
console.log(`$${tokenName} current price on the open market: ${lastTransactionPrice} ${cryptoName}`);
fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${cryptoNameLc}&vs_currencies=usd`)
.then(response => response.json())
.then(data => {
const priceUSD = data[cryptoNameLc].usd;
console.log(`$${cryptoName} current price is $ ${priceUSD}`);
const tokenPriceUSD = lastTransactionPrice * priceUSD;
console.log(`The current price of $${tokenName} is $ ${tokenPriceUSD.toFixed(4)}.`);
});
};
var tokenPair = {
tokenName: 'BOOM',
contract: 'csboomcsboom',
cryptoName: 'WAX',
marketNumber: 368,
};
getFungibleTokenPrice({ tokenPair });
From a conversation with crim:
We plan on broadcasting a custom_json operation on chain with the match summary at the end of every 5-min PVP match. It will contain the match participants (max 8 per room), match result and kill log.
ie.
{
"matchId": "MTcwNzUxNDc5NDYzNC1jcnlwdG9zaG90cy5uZnQtcHZl",
"startTime": 1707514794634,
"endTime": 1707514865805,
"mode": "PVP",
"map": 0,
"players": ["pvp-player1", "pvp-player2"],
"winner": "team-alpha",
"killLog": ["0-1:10","1-0:160","0-1:240"]
}
This way Dappradar should be able to track active users by using the players array field.
So same here, we plan on broadcasting a custom_json operation on chain after every PVE match with the player name and match result.
{
"matchId": "MTcwNzUxNDc5NDYzNC1jcnlwdG9zaG90cy5uZnQtcHZw",
"startTime": 1707514794634,
"endTime": 1707514865805,
"mode": "PVE",
"map": 2,
"players": ["some-pve-player"],
"winner": "bots",
"killLog": ["1:10","0:16","2:24", "0:32", "0:45"]
}
This way Dappradar should be able to track active users by using the players array field.
How does a custom_json operation on the Hive blockchain looks like:
block_num 82670298
expiration 2024-02-09T23:53:30
extensions []
operations [["custom_json", {"id": "ssc-mainnet-hive", "json": "{\"contractName\":\"tokens\",\"contractAction\":\"stake\",\"contractPayload\":{\"symbol\":\"DOOM\",\"to\":\"athunderstruck\",\"quantity\":\"6.6700\",\"memo\":\"Crypto Shots PVP Alpha reward. GG!\"}}", "required_auths": ["cryptoshots.tips"], "required_posting_auths": [] }]]
ref_block_num 29401
ref_block_prefix 2126063433
signatures [ "1f5054e3996f04805b4a7b070c78d94cd50ee8097094f832335b7119199ca421470e6a5a6c6e63c6dc272eb6ca549761b4c176f209eb3de0a049ccbbc9e3472057" ]
transaction_id 9ee3b9672bf71e0e5d853cb44dfb275ed2fd46a8
transaction_num 80
Example of how to stream blocks of the Hive blockchain and parse custom_json operations found in blocks:
const fetch = require('node-fetch');
const { Client, Blockchain } = require('@hiveio/dhive');
const fetchHealthyHiveNode = () => fetch(
'https://beacon.peakd.com/api/nodes',
{
credentials: 'omit',
headers: { Accept: 'application/json' },
method: 'GET',
},
)
.then((res) => res.json())
.then((allNodes) => {
const healthyNodes = allNodes.filter(({ score } = {}) => score === 100);
return ({ hiveNode: healthyNodes[0].endpoint });
})
.catch((fetchErr) => ({ err: `Url fetch failed: ${fetchErr}` }));
const streamBlocks = async () => {
const { err, hiveNode } = await fetchHealthyHiveNode();
if (err) return;
const client = new Client(hiveNode);
const blockchain = new Blockchain(client);
console.log('Streaming blocks from', hiveNode);
blockchain.getBlockStream()
.on('data', (block) => {
console.log(`Received block #${block.block_id} containing ${block.transactions.length} transactions`);
block.transactions.forEach(
tx => tx.operations.forEach(
op => op[0] === 'custom_json' && console.log(op[1]),
)
);
})
.on('error', console.error);
};
streamBlocks();
- (( For transparency every 15th of the month we also take a snapshot and post all game stats (json) on the Hive chain at the same permlink, but I doubt they can consume that. ))
crim:
Is there enough data right now from HE not being tracked that adding it would make a big difference?
gabe:
RE: Wiki