The RpcClient encapsulates all the interfaces provided by RpcServer. You can send RPC requests in your code through the standard methods provided in this module. You only need to pass in the corresponding parameters, the SDK will construct the corresponding JSON-RPC requests and then get the data returned by the node.
Initializing RpcClient
Before you can send RPC requests you need to initialize RpcClient first. Choose the RPC server port of a Neo node according to your own needs. Here is an example:
Test net node:
Local node (the local Neo-CLI that can be connected to main net, test net, or private net according to configuration):
Typically, only one RpcClient instance needs to be initialized in an application, not needing in each method.
Blockchain data
GetBestBlockHashAsync
Gets the hash of the highest block in the blockchain:
GetBlockAsync
Gets the detailed block information by the block hash or block index.
or
You can also get the serialized block information through the block hash value or block index:
Get the specific block header information by the block hash or block index:
or
Get the serialized block header information from the block hash or block index:
or
GetContractStateAsync
Gets the contract information from the contract hash or contract ID
GetRawMempoolAsync
Gets hash list of the confirmed transactions in the memory.
GetRawMempoolBothAsync
Gets both confirmed and unconfirmed transaction hashes in memory:
GetRawTransactionAsync
Gets the transaction information by transaction ID.
GetRawTransactionHexAsync
Gets the serialized transaction by transaction ID.
CalculateNetworkFeeAsync
Calculates network fee of the specified transaction.
GetStorageAsync
Gets the stored value through the contract script hash and stored key (which needs to be converted into a hex string):
GetTransactionHeightAsync
Gets the block height of the specified transaction by transaction ID:
GetNextBlockValidatorsAsync
Gets the consensus nodes information and voting status in the current network.
GetCommitteeAsync
Gets the public key list of the current committee members.
Node
GetConnectionCount
Gets the number of nodes connected to this node.
GetPeersAsync
Gets a list of currently connected / unconnected nodes for this node, including IP address and port.
GetVersionAsync
Gets the version of the node receiving the RPC request:
SendRawTransactionAsync
Sends and broadcasts the serialized transaction.
Or broadcasts the transaction (tx) over the blockchain:
SubmitBlockAsync
Sends and broadcasts the serialized block:
Smart contract
InvokeFunctionAsync
Invokes the specific method of the smart contract through the specified smart contract script hash, method name, and parameters, and returns the result after running in the virtual machine.
InvokeScriptAsync
Returns the result after running the specified script in the virtual machine.
GetUnclaimedGasAsync
Gets amount of unclaimed GAS at the specified address.
Tools
ListPluginsAsync
Lists all the plugins loaded in the node.
ValidateAddressAsync
Validates if the specified address is a valid Neo address.
Wallets
The node local wallet interface contains the function of accessing the local wallet file. Before using the methods described in this section, you need to open the wallet using the openwallet method.
This method is disabled by default in the node configuration file for preventing high security risks.
OpenWalletAsync
Opens the wallet file in the machine running the node.
CloseWalletAsync
Closes the wallet and clears the wallet information in memory.
DumpPrivKeyAsync
Exports the private key of the specified address.
GetBalanceAsync
Returns balance of the specified asset in the wallet by the asset id. This method is applicable to the native contract assets and NEP-17 compliant assets.
GetNewAddressAsync
Creates a new account in the wallet and returns the corresponding address.
GetUnclaimedGasAsync
Displays amount of the unclaimed GAS in the wallet.
ImportPrivKeyAsync
Imports the private key into the wallet.
ListAddressAsync
Lists all the addresses in the wallet.
SendFromAsync
Transfers asset from a specified address to another address.
If the JSON transaction information is returned the transaction was sent successfully, or the transaction failed to be sent.
If the signature is incomplete transaction to be signed is returned.
If the balance is insufficient an error is returned.
SendManyAsync
Transfers assets to multiple addresses. You can specify the sending address.
If the JSON transaction information is returned the transaction was sent successfully, or the transaction failed to be sent.
If the signature is incomplete transaction to be signed is returned.
If the balance is insufficient an error is returned.
SendToAddressAsync
Transfers asset to the specified address.
If the JSON transaction information is returned the transaction was sent successfully, or the transaction failed to be sent.
If the signature is incomplete transaction to be signed is returned.
If the balance is insufficient an error is returned.
Plugins
GetApplicationLogAsync
Gets the contract log by the specific transaction ID. The plugin ApplicationLogs is required for invoking this method.
Or gets the contract log based on the specified transaction ID and trigger type
GetNep17BalancesAsync
Returns all NEP-17 assets balance at the specified address. The plugin TokensTracker is required for invoking this method.
GetNep17TransfersAsync
Returns all NEP-17 transaction records at the specific address. The plugin TokensTracker is required for invoking this method.
If start and end timestamps are specified, transactions occurred in the time range is returned.
If no parameter is specified transactions in the past seven days are returned.