importjsonimportosimporturllib.requestfromsymbolchain.CryptoTypesimportPublicKeyfromsymbolchain.facade.NemFacadeimportNemFacadeNODE_URL=os.getenv('NODE_URL','http://libertalia.nemtest.net:7890')print(f'Using node {NODE_URL}')BLOCK_HEIGHT=os.getenv('BLOCK_HEIGHT','661258')facade=NemFacade('testnet')try:# Fetch the block at the given heightblock_url=f'{NODE_URL}/block/at/public'request=urllib.request.Request(block_url,data=json.dumps({'height':int(BLOCK_HEIGHT)}).encode(),headers={'Content-Type':'application/json'})withurllib.request.urlopen(request)asresponse:block=json.loads(response.read())transactions=block['transactions']print(f'Block height: {BLOCK_HEIGHT}')print(f'Transactions: {len(transactions)}')# Identify the harvesterharvester=facade.network.public_key_to_address(PublicKey(block['signer']))print(f'Harvester: {harvester}')# Sum the transaction feestotal_reward=0print('\nTransaction fees:')fortransactionintransactions:fee=int(transaction['fee'])total_reward+=feeprint(f' Fee: {fee/1e6:,.6f} XEM')# Total rewardprint(f'\nTotal block reward: {total_reward/1e6:,.6f} XEM')exceptExceptionaserror:print(error)
import{PublicKey}from'symbol-sdk';import{NemFacade}from'symbol-sdk/nem';constfmt=v=>(Number(v)/1e6).toLocaleString('en-US',{minimumFractionDigits:6});constNODE_URL=process.env.NODE_URL||'http://libertalia.nemtest.net:7890';console.log(`Using node ${NODE_URL}`);constBLOCK_HEIGHT=process.env.BLOCK_HEIGHT||'661258';constfacade=newNemFacade('testnet');try{// Fetch the block at the given heightconstblockUrl=`${NODE_URL}/block/at/public`;constresponse=awaitfetch(blockUrl,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({height:parseInt(BLOCK_HEIGHT,10)})});if(!response.ok)thrownewError(`HTTP error! status: ${response.status}`);constblock=awaitresponse.json();consttransactions=block.transactions;console.log(`Block height: ${BLOCK_HEIGHT}`);console.log(`Transactions: ${transactions.length}`);// Identify the harvesterconstharvester=facade.network.publicKeyToAddress(newPublicKey(block.signer));console.log(`Harvester: ${harvester}`);// Sum the transaction feeslettotalReward=0n;console.log('\nTransaction fees:');for(consttransactionoftransactions){constfee=BigInt(transaction.fee);totalReward+=fee;console.log(` Fee: ${fmt(fee)} XEM`);}// Total rewardconsole.log(`\nTotal block reward: ${fmt(totalReward)} XEM`);}catch(error){console.log(error);}
# Fetch the block at the given heightblock_url=f'{NODE_URL}/block/at/public'request=urllib.request.Request(block_url,data=json.dumps({'height':int(BLOCK_HEIGHT)}).encode(),headers={'Content-Type':'application/json'})withurllib.request.urlopen(request)asresponse:block=json.loads(response.read())transactions=block['transactions']print(f'Block height: {BLOCK_HEIGHT}')print(f'Transactions: {len(transactions)}')
// Fetch the block at the given heightconstblockUrl=`${NODE_URL}/block/at/public`;constresponse=awaitfetch(blockUrl,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({height:parseInt(BLOCK_HEIGHT,10)})});if(!response.ok)thrownewError(`HTTP error! status: ${response.status}`);constblock=awaitresponse.json();consttransactions=block.transactions;console.log(`Block height: ${BLOCK_HEIGHT}`);console.log(`Transactions: ${transactions.length}`);
# Sum the transaction feestotal_reward=0print('\nTransaction fees:')fortransactionintransactions:fee=int(transaction['fee'])total_reward+=feeprint(f' Fee: {fee/1e6:,.6f} XEM')
// Sum the transaction feeslettotalReward=0n;console.log('\nTransaction fees:');for(consttransactionoftransactions){constfee=BigInt(transaction.fee);totalReward+=fee;console.log(` Fee: ${fmt(fee)} XEM`);}