importjsonimportosimporturllib.requestfromsymbolchain.CryptoTypesimportPublicKeyfromsymbolchain.symbol.NetworkimportAddress,NetworkNODE_URL=os.getenv('NODE_URL','https://reference.symboltest.net:3001')print(f'Using node {NODE_URL}')BLOCK_HEIGHT=os.getenv('BLOCK_HEIGHT','3222290')deffmt(val):# Format atomic amounts as whole XYM with integer math,# since amounts can exceed float precision.returnf'{val//10**6:,}.{val%10**6:06d}'try:# Get the block headerblock_url=f'{NODE_URL}/blocks/{BLOCK_HEIGHT}'withurllib.request.urlopen(block_url)asresponse:block=json.loads(response.read())signer=Network.TESTNET.public_key_to_address(PublicKey(block['block']['signerPublicKey']))beneficiary=block['block']['beneficiaryAddress']print(f'Block height: {BLOCK_HEIGHT}')print(f'Signer: {signer}')beneficiary_b32=Address.from_decoded_address_hex_string(beneficiary)print(f'Beneficiary: {beneficiary_b32}')# Get the network sink addressproperties_url=f'{NODE_URL}/network/properties'withurllib.request.urlopen(properties_url)asresponse:properties=json.loads(response.read())sink_b32=properties['chain']['harvestNetworkFeeSinkAddress']sink=Address(sink_b32).bytes.hex().upper()print(f'Network sink: {sink_b32}')# Get the inflation reward at this heightinflation_url=f'{NODE_URL}/network/inflation/at/{BLOCK_HEIGHT}'withurllib.request.urlopen(inflation_url)asresponse:inflation=json.loads(response.read())reward=int(inflation['rewardAmount'])print(f'Inflation reward: {fmt(reward)} XYM')# Get harvest fee receipts for this blockreceipts_url=(f'{NODE_URL}/statements/transaction'f'?height={BLOCK_HEIGHT}'f'&receiptType=8515')withurllib.request.urlopen(receipts_url)asresponse:receipts=json.loads(response.read())# Label and display the reward distributiontotal=0print('\nReward distribution:')foriteminreceipts['data']:forrinitem['statement']['receipts']:ifr['type']!=8515:continueamount=int(r['amount'])total+=amounttarget=r['targetAddress']iftarget==sink:label='Network sink (5%)'eliftarget==beneficiary:label='Beneficiary (25%)'else:label='Harvester'harvester_addr=Address.from_decoded_address_hex_string(target)print(f' Harvester address: {harvester_addr}')print(f' {label}: {fmt(amount)} XYM')# Summaryfees=total-rewardprint('\nSummary:')print(f' Total block reward: {fmt(total)} XYM')print(f' Inflation: {fmt(reward)} XYM')print(f' Transaction fees: {fmt(fees)} XYM')exceptExceptionaserror:print(error)
import{PublicKey}from'symbol-sdk';import{Address,Network}from'symbol-sdk/symbol';// Format an atomic amount (BigInt) as whole XYM.// A float division would lose precision on large amounts.constfmt=v=>`${(v/1_000_000n).toLocaleString('en-US')}.`+`${(v%1_000_000n).toString().padStart(6,'0')}`;constNODE_URL=process.env.NODE_URL||'https://reference.symboltest.net:3001';console.log(`Using node ${NODE_URL}`);constBLOCK_HEIGHT=process.env.BLOCK_HEIGHT||'3222290';// Get the block headerconstblockUrl=`${NODE_URL}/blocks/${BLOCK_HEIGHT}`;constblock=await(awaitfetch(blockUrl)).json();constsigner=Network.TESTNET.publicKeyToAddress(newPublicKey(block.block.signerPublicKey));constbeneficiary=block.block.beneficiaryAddress;console.log(`Block height: ${BLOCK_HEIGHT}`);console.log(`Signer: ${signer}`);constbeneficiaryB32=Address.fromDecodedAddressHexString(beneficiary);console.log(`Beneficiary: ${beneficiaryB32}`);// Get the network sink addressconstpropertiesUrl=`${NODE_URL}/network/properties`;constproperties=await(awaitfetch(propertiesUrl)).json();constsinkB32=properties.chain.harvestNetworkFeeSinkAddress;constsink=Array.from(newAddress(sinkB32).bytes).map(b=>b.toString(16).padStart(2,'0')).join('').toUpperCase();console.log(`Network sink: ${sinkB32}`);// Get the inflation reward at this heightconstinflationUrl=`${NODE_URL}/network/inflation/at/${BLOCK_HEIGHT}`;constinflation=await(awaitfetch(inflationUrl)).json();constreward=BigInt(inflation.rewardAmount);console.log(`Inflation reward: ${fmt(reward)} XYM`);// Get harvest fee receipts for this blockconstreceiptsUrl=`${NODE_URL}/statements/transaction`+`?height=${BLOCK_HEIGHT}&receiptType=8515`;constreceipts=await(awaitfetch(receiptsUrl)).json();// Label and display the reward distributionlettotal=0n;console.log('\nReward distribution:');for(constitemofreceipts.data){for(constrofitem.statement.receipts){if(8515===r.type){constamount=BigInt(r.amount);total+=amount;letlabel;if(r.targetAddress===sink){label='Network sink (5%)';}elseif(r.targetAddress===beneficiary){label='Beneficiary (25%)';}else{label='Harvester';constharvesterAddress=Address.fromDecodedAddressHexString(r.targetAddress);console.log(` Harvester address: ${harvesterAddress}`);}console.log(` ${label}: ${fmt(amount)} XYM`);}}}// Summaryconstfees=total-reward;console.log('\nSummary:');console.log(` Total block reward: ${fmt(total)} XYM`);console.log(` Inflation: ${fmt(reward)} XYM`);console.log(` Transaction fees: ${fmt(fees)} XYM`);
//JAVA 21+//DEPS org.symbol:symbol-sdk:3.3.1importjava.io.IOException;importjava.math.BigInteger;importjava.net.URI;importjava.net.http.HttpClient;importjava.net.http.HttpRequest;importjava.net.http.HttpResponse;importjava.net.http.HttpResponse.BodyHandlers;importjava.util.HexFormat;importjava.util.Locale;importcom.fasterxml.jackson.databind.JsonNode;importcom.fasterxml.jackson.databind.ObjectMapper;importorg.symbol.sdk.CryptoTypes;importorg.symbol.sdk.symbol.Address;importorg.symbol.sdk.symbol.Network;finalclassQueryBlockRewards{privatestaticfinalHttpClientHTTP_CLIENT=HttpClient.newHttpClient();privatestaticfinalObjectMapperJSON_MAPPER=newObjectMapper();privatestaticfinalStringNODE_URL=System.getenv().getOrDefault("NODE_URL","https://reference.symboltest.net:3001");privatestaticfinalStringBLOCK_HEIGHT=System.getenv().getOrDefault("BLOCK_HEIGHT","3222290");privatestaticJsonNodefetchJson(finalStringpath)throwsIOException,InterruptedException{finalStringurl=String.format("%s%s",NODE_URL,path);finalHttpRequestrequest=HttpRequest.newBuilder(URI.create(url)).GET().build();finalHttpResponse<String>response=HTTP_CLIENT.send(request,BodyHandlers.ofString());returnJSON_MAPPER.readTree(response.body());}// Format an atomic amount as whole XYM with integer math,// since amounts can exceed float precision.privatestaticStringfmt(finalBigIntegervalue){finalBigIntegerdivisor=BigInteger.valueOf(1_000_000);finalBigInteger[]parts=value.divideAndRemainder(divisor);returnString.format(Locale.US,"%,d.%06d",parts[0],parts[1]);}publicstaticvoidmain(finalString[]args){newQueryBlockRewards().run();}privatevoidrun(){System.out.printf("Using node %s%n",NODE_URL);try{// Get the block headerfinalStringblockPath=String.format("/blocks/%s",BLOCK_HEIGHT);finalJsonNodeblock=fetchJson(blockPath);finalJsonNodeblockHeader=block.get("block");finalCryptoTypes.PublicKeysignerPublicKey=newCryptoTypes.PublicKey(blockHeader.get("signerPublicKey").asText());finalAddresssigner=Network.TESTNET.publicKeyToAddress(signerPublicKey);finalStringbeneficiary=blockHeader.get("beneficiaryAddress").asText();System.out.printf("Block height: %s%n",BLOCK_HEIGHT);System.out.printf("Signer: %s%n",signer);finalAddressbeneficiaryB32=Address.fromDecodedAddressHexString(beneficiary);System.out.printf("Beneficiary: %s%n",beneficiaryB32);// Get the network sink addressfinalJsonNodeproperties=fetchJson("/network/properties");finalStringsinkB32=properties.get("chain").get("harvestNetworkFeeSinkAddress").asText();finalStringsink=HexFormat.of().formatHex(newAddress(sinkB32).bytes()).toUpperCase(Locale.ROOT);System.out.printf("Network sink: %s%n",sinkB32);// Get the inflation reward at this heightfinalStringinflationPath=String.format("/network/inflation/at/%s",BLOCK_HEIGHT);finalJsonNodeinflation=fetchJson(inflationPath);finalBigIntegerreward=newBigInteger(inflation.get("rewardAmount").asText());System.out.printf("Inflation reward: %s XYM%n",fmt(reward));// Get harvest fee receipts for this blockfinalStringreceiptsPath=String.format("/statements/transaction?height=%s&receiptType=8515",BLOCK_HEIGHT);finalJsonNodereceipts=fetchJson(receiptsPath);// Label and display the reward distributionBigIntegertotal=BigInteger.ZERO;System.out.println("\nReward distribution:");for(finalJsonNodeitem:receipts.get("data")){for(finalJsonNodereceipt:item.get("statement").get("receipts")){if(8515!=receipt.get("type").asInt())continue;finalBigIntegeramount=newBigInteger(receipt.get("amount").asText());total=total.add(amount);finalStringtarget=receipt.get("targetAddress").asText();finalStringlabel;if(target.equals(sink)){label="Network sink (5%)";}elseif(target.equals(beneficiary)){label="Beneficiary (25%)";}else{label="Harvester";finalAddressharvesterAddress=Address.fromDecodedAddressHexString(target);System.out.printf(" Harvester address: %s%n",harvesterAddress);}System.out.printf(" %s: %s XYM%n",label,fmt(amount));}}// SummaryfinalBigIntegerfees=total.subtract(reward);System.out.println("\nSummary:");System.out.printf(" Total block reward: %s XYM%n",fmt(total));System.out.printf(" Inflation: %s XYM%n",fmt(reward));System.out.printf(" Transaction fees: %s XYM%n",fmt(fees));}catch(finalExceptionex){System.out.println(ex.getMessage());}}}
# Get the block headerblock_url=f'{NODE_URL}/blocks/{BLOCK_HEIGHT}'withurllib.request.urlopen(block_url)asresponse:block=json.loads(response.read())signer=Network.TESTNET.public_key_to_address(PublicKey(block['block']['signerPublicKey']))beneficiary=block['block']['beneficiaryAddress']print(f'Block height: {BLOCK_HEIGHT}')print(f'Signer: {signer}')beneficiary_b32=Address.from_decoded_address_hex_string(beneficiary)print(f'Beneficiary: {beneficiary_b32}')
// Get the block headerconstblockUrl=`${NODE_URL}/blocks/${BLOCK_HEIGHT}`;constblock=await(awaitfetch(blockUrl)).json();constsigner=Network.TESTNET.publicKeyToAddress(newPublicKey(block.block.signerPublicKey));constbeneficiary=block.block.beneficiaryAddress;console.log(`Block height: ${BLOCK_HEIGHT}`);console.log(`Signer: ${signer}`);constbeneficiaryB32=Address.fromDecodedAddressHexString(beneficiary);console.log(`Beneficiary: ${beneficiaryB32}`);
// Get the block headerfinalStringblockPath=String.format("/blocks/%s",BLOCK_HEIGHT);finalJsonNodeblock=fetchJson(blockPath);finalJsonNodeblockHeader=block.get("block");finalCryptoTypes.PublicKeysignerPublicKey=newCryptoTypes.PublicKey(blockHeader.get("signerPublicKey").asText());finalAddresssigner=Network.TESTNET.publicKeyToAddress(signerPublicKey);finalStringbeneficiary=blockHeader.get("beneficiaryAddress").asText();System.out.printf("Block height: %s%n",BLOCK_HEIGHT);System.out.printf("Signer: %s%n",signer);finalAddressbeneficiaryB32=Address.fromDecodedAddressHexString(beneficiary);System.out.printf("Beneficiary: %s%n",beneficiaryB32);
# Get the network sink addressproperties_url=f'{NODE_URL}/network/properties'withurllib.request.urlopen(properties_url)asresponse:properties=json.loads(response.read())sink_b32=properties['chain']['harvestNetworkFeeSinkAddress']sink=Address(sink_b32).bytes.hex().upper()print(f'Network sink: {sink_b32}')
// Get the network sink addressconstpropertiesUrl=`${NODE_URL}/network/properties`;constproperties=await(awaitfetch(propertiesUrl)).json();constsinkB32=properties.chain.harvestNetworkFeeSinkAddress;constsink=Array.from(newAddress(sinkB32).bytes).map(b=>b.toString(16).padStart(2,'0')).join('').toUpperCase();console.log(`Network sink: ${sinkB32}`);
// Get the network sink addressfinalJsonNodeproperties=fetchJson("/network/properties");finalStringsinkB32=properties.get("chain").get("harvestNetworkFeeSinkAddress").asText();finalStringsink=HexFormat.of().formatHex(newAddress(sinkB32).bytes()).toUpperCase(Locale.ROOT);System.out.printf("Network sink: %s%n",sinkB32);
# Get the inflation reward at this heightinflation_url=f'{NODE_URL}/network/inflation/at/{BLOCK_HEIGHT}'withurllib.request.urlopen(inflation_url)asresponse:inflation=json.loads(response.read())reward=int(inflation['rewardAmount'])print(f'Inflation reward: {fmt(reward)} XYM')
// Get the inflation reward at this heightconstinflationUrl=`${NODE_URL}/network/inflation/at/${BLOCK_HEIGHT}`;constinflation=await(awaitfetch(inflationUrl)).json();constreward=BigInt(inflation.rewardAmount);console.log(`Inflation reward: ${fmt(reward)} XYM`);
// Get the inflation reward at this heightfinalStringinflationPath=String.format("/network/inflation/at/%s",BLOCK_HEIGHT);finalJsonNodeinflation=fetchJson(inflationPath);finalBigIntegerreward=newBigInteger(inflation.get("rewardAmount").asText());System.out.printf("Inflation reward: %s XYM%n",fmt(reward));
# Get harvest fee receipts for this blockreceipts_url=(f'{NODE_URL}/statements/transaction'f'?height={BLOCK_HEIGHT}'f'&receiptType=8515')withurllib.request.urlopen(receipts_url)asresponse:receipts=json.loads(response.read())# Label and display the reward distributiontotal=0print('\nReward distribution:')foriteminreceipts['data']:forrinitem['statement']['receipts']:ifr['type']!=8515:continueamount=int(r['amount'])total+=amounttarget=r['targetAddress']iftarget==sink:label='Network sink (5%)'eliftarget==beneficiary:label='Beneficiary (25%)'else:label='Harvester'harvester_addr=Address.from_decoded_address_hex_string(target)print(f' Harvester address: {harvester_addr}')print(f' {label}: {fmt(amount)} XYM')
// Get harvest fee receipts for this blockconstreceiptsUrl=`${NODE_URL}/statements/transaction`+`?height=${BLOCK_HEIGHT}&receiptType=8515`;constreceipts=await(awaitfetch(receiptsUrl)).json();// Label and display the reward distributionlettotal=0n;console.log('\nReward distribution:');for(constitemofreceipts.data){for(constrofitem.statement.receipts){if(8515===r.type){constamount=BigInt(r.amount);total+=amount;letlabel;if(r.targetAddress===sink){label='Network sink (5%)';}elseif(r.targetAddress===beneficiary){label='Beneficiary (25%)';}else{label='Harvester';constharvesterAddress=Address.fromDecodedAddressHexString(r.targetAddress);console.log(` Harvester address: ${harvesterAddress}`);}console.log(` ${label}: ${fmt(amount)} XYM`);}}}
// Get harvest fee receipts for this blockfinalStringreceiptsPath=String.format("/statements/transaction?height=%s&receiptType=8515",BLOCK_HEIGHT);finalJsonNodereceipts=fetchJson(receiptsPath);// Label and display the reward distributionBigIntegertotal=BigInteger.ZERO;System.out.println("\nReward distribution:");for(finalJsonNodeitem:receipts.get("data")){for(finalJsonNodereceipt:item.get("statement").get("receipts")){if(8515!=receipt.get("type").asInt())continue;finalBigIntegeramount=newBigInteger(receipt.get("amount").asText());total=total.add(amount);finalStringtarget=receipt.get("targetAddress").asText();finalStringlabel;if(target.equals(sink)){label="Network sink (5%)";}elseif(target.equals(beneficiary)){label="Beneficiary (25%)";}else{label="Harvester";finalAddressharvesterAddress=Address.fromDecodedAddressHexString(target);System.out.printf(" Harvester address: %s%n",harvesterAddress);}System.out.printf(" %s: %s XYM%n",label,fmt(amount));}}