Skip to main content

Getting Blockchain Information

The RPC module provides methods to get basic information of blockchain data and status, such as block height, block content, transaction details, and contracts.

For some specific information of contracts, such as the block maximum transaction number, system fee per byte, NEP-17 contract details, you need to invoke specific contract methods, which will be introduced in this document.

Getting blockchain data from RPC interfaces#

Gets the latest block height or hash:

// choose a neo node with rpc openedRpcClient client = new RpcClient(new Uri("http://localhost:20332"), null, null, ProtocolSettings.Load("config.json"));
// get the hash of the tallest block in the main chainstring hash = await client.GetBestBlockHashAsync().ConfigureAwait(false);
// get the number of blocks in the main chainuint count = await client.GetBlockCountAsync().ConfigureAwait(false);

Gets the specific data inside a block, including transaction list, etc.

// get the Base64 string of the block with block heightstring blockHex = await client.GetBlockHexAsync("166396").ConfigureAwait(false);
// get the Base64 string of the block with block hashstring blockHex = await client.GetBlockHexAsync("0x4e61cd9d76e30e9147ee0f5b9c92f4447decbe52c6c8b412d0382a14d3a0b408").ConfigureAwait(false);
// get block data with block heightRpcBlock block = await client.GetBlockAsync("166396").ConfigureAwait(false);
// get block data with block hashRpcBlock block = await client.GetBlockAsync("0x4e61cd9d76e30e9147ee0f5b9c92f4447decbe52c6c8b412d0382a14d3a0b408").ConfigureAwait(false);

Gets the contract script, hash, and manifest through RpcClient:

// get NEO contract stateContractState contractState = await client.GetContractStateAsync(NativeContract.NEO.Hash.ToString()).ConfigureAwait(false);

For more information refer to RPC invocation methods.

Getting policy information#

Invokes the method policyAPI in the native contract PolicyContract to get the Policy related information:

// choose a neo node with rpc openedPolicyAPI policyAPI = new PolicyAPI(new RpcClient(new Uri("http://localhost:20332"), null,null, ProtocolSettings.Load("config.json")));
// get the system fee per bytelong feePerByte = await policyAPI.GetFeePerByteAsync().ConfigureAwait(false); // 1000, 0.00001000 GAS per byte
// get the max size of one blockuint maxBlockSize = await policyAPI.GetMaxBlockSizeAsync().ConfigureAwait(false); // 262144, (1024 * 256) bytes one block
// get the max transaction count per blockuint maxTransactionsPerBlock = await policyAPI.GetMaxTransactionsPerBlockAsync().ConfigureAwait(false); // 512, max 512 transactions one block
// check if the account is blockedUInt160 account = Utility.GetScriptHash("NirHUAteaMr6CqWuAAMaEUScPcS3FDKebM");bool isBlocked = await policyAPI.IsBlockedAsync(account).ConfigureAwait(false);

Getting NEP-17 contract information#

NEP17 is an asset standard for Neo N3, such as NEO and GAS, both of which are assets based on NEP17 native contract. You can invoke Nep17API to get the name, mark, decimal place, and amount of the NEP17 contract.

// get nep17 token infoNep17API nep17API = new Nep17API(new RpcClient(new Uri("http://localhost:20332"), null,null, ProtocolSettings.Load("config.json")));RpcNep17TokenInfo tokenInfo = await nep17API.GetTokenInfoAsync(NativeContract.NEO.Hash).ConfigureAwait(false);