Version
Show / Hide Table of Contents

API Reference

Each NEO-CLI node provides an API interface for obtaining blockchain data from it, making it easy to develop blockchain applications. The interface is provided via JSON-RPC , and the underlying protocol uses HTTP/HTTPS for communication. To start a node that provides an RPC service, run the following command:

dotnet neo-cli.dll /rpc

Listening ports

After the JSON-RPC server starts, it will monitor the following ports, corresponding to the Main and Test nets:

For P2P and WebSocket information see Node Introduction .

Main NetTest Net
JSON-RPC HTTPS1033120331
JSON-RPC HTTP1033220332

Command List

CommandReferenceExplanationComments
claimgas [address]Claims GAS in the wallet.Need to open the wallet
dumpprivkey <address>Exports the private key of the specified addressNeed to open the wallet
getaccountstate <address>Checks account asset information according to account address
getapplicationlog <txid>Returns the contract log based on the specified txid.
getassetstate <asset_id>Queries asset information according to the specified asset number
getbalance <asset_id>Returns the balance of the corresponding asset in the wallet according to the specified asset number.Need to open the wallet
getbestblockhash Gets the hash of the tallest block in the main chain
getblock <hash> [verbose=0]Returns the corresponding block information according to the specified hash value
getblock <index> [verbose=0]Returns the corresponding block information according to the specified index
getblockcount Gets the number of blocks in the main chain
getblockhash <index>Returns the hash value of the corresponding block based on the specified index
getblockheader <hash> [verbose=0]Returns the corresponding block header information according to the specified script hash
getblocksysfee <index>Returns the system fees before the block according to the specified index
getclaimable <address>Returns claimable GAS information of the specified address.
getconnectioncount Gets the current number of connections for the node
getcontractstate <script_hash>Returns information about the contract based on the specified script hash
getmetricblocktimestamp <blocks numbers> <endHeight>Returns timestamps of the specified block and its previous n blocks.
getnep5balances <address>Returns the balance of all NEP-5 assets in the specified address.
getnep5transfers <address>Returns all the NEP-5 transaction information occurred in the specified address.
getnewaddress Creates a new addressNeed to open the wallet
getrawmempool Gets a list of confirmed / unconfirmed transactions in memory.
getrawtransaction <txid> [verbose=0]Returns the corresponding transaction information based on the specified hash value
getunclaimed <address>Returns unclaimed GAS amount of the specified address.
getunclaimedgas Gets the amount of unclaimed GAS in the wallet.Need to open the wallet
getunspents <address>Returns information of the unspent UTXO assets at the specified address.
getutxotransfers <address> asset Returns UTXO transaction information occurred in the specified time period for the specified address.
getstateheight Gets the latest block height and the the verified state height.
getstateroot <key>Gets the state root information of the block.
getstorage <script_hash> <key>Returns the stored value based on the contract script hash and key
gettransactionheight <txid>Returns the block index in which the transaction is found.
gettxout <txid> <n>Returns the corresponding transaction output (change) information based on the specified hash and index
getpeers Gets a list of nodes that are currently connected/disconnected by this node
getproof <stateroot> <scripthash> <key>Gets proof of the stored value according to the specified StateRoot, contract script hash, and the stored key.
getversion Gets version information of this node
getvalidators Gets NEO consensus nodes information
getwalletheight Gets the current wallet index height.Need to open the wallet
importprivkey <key>Imports the private key to the wallet.Need to open the wallet
invokefunction <script_hash> <operation> <params>Invokes a smart contract at specified script hash, passing in an operation and its params
invokescript <script>Runs a script through the virtual machine and returns the results
listaddress Lists all the addresses in the current wallet.Need to open the wallet
listplugins Returns a list of plugins loaded by the node.
sendrawtransaction <hex>Broadcast a transaction over the network.
sendfrom <asset_id> <address> <value> [fee=0]Transfers from the specified address to the destination address.Need to open the wallet
sendtoaddress <asset_id> <address> <value> [fee=0]Transfer to specified addressNeed to open the wallet
sendmany <outputsarray> [fee=0] [changeaddress]Bulk transfer orderNeed to open the wallet
submitblock <hex>Relay a new block to the networkNeeds to be a consensus node
validateaddress <address>Verify that the address is a correct NEO address
verifyproof <state_root> <proof>Gets the calculated value according to StateRoot and proof.

GET request example

The format of a typical JSON-RPC GET request is as follows:

Here is an example of how to get the number of blocks in the main chain.

Request URL:

http://somewebsite.com:10332?jsonrpc=2.0&method=getblockcount&params=[]&id=1

After sending the request, you will get the following response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": 909129
}

POST request example

The format of a typical JSON-RPC Post request is as follows:

Here is an example of how to get the number of blocks in the main chain.

Request URL:

http://somewebsite.com:10332

Request Body:

{
  "jsonrpc": "2.0",
  "method": "getblockcount",
  "params":[],
  "id": 1
}

After sending the request, you will get the following response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": 909122
}

Test tools

You can use the Chrome extension in Postman to facilitate the test (Installation of the Chrome extension requires Internet connection). A test screenshot is shown below:

image

Other

C# JSON-RPC Command List