-
UPDATE
- Invocation Style: getblockheader,getrawmempool
- Returns: getblock,getblockheader,getrawtransaction,getversion,getcontractstate
-
DELETE
- Discard the following commands:
claimgas
,getaccountstate
,getassetstate
,getclaimable
,getmetricblocktimestamp
,gettxout
,getunspents
,invoke
- Discard the following commands:
Neo-CLI provides a set of API interfaces for obtaining blockchain data from a node to facilitate the development of blockchain applications. The interface is provided via JSON-RPC and employs HTTP/HTTPS as the underlying protocol for communication. You can run the following command to install the RpcServer plugin:
install RpcServer
-
HTTPS: To access the RPC server via HTTPS, you need to set the domain name, certificate and password in the configuration file
config.json
of theRpcServer
before installing the plugin:{ "PluginConfiguration": { "BindAddress": "127.0.0.1", "Port": 10332, "SslCert": "YourSslCertFile.xxx", "SslCertPassword": "YourPassword", "TrustedAuthorities": [], "RpcUser": "", "RpcPass": "", "MaxGasInvoke": 10, "MaxFee": 0.1, "MaxConcurrentConnections": 40, "DisabledMethods": [] }
-
Open the wallet: If you want to invoke wallet-related methods through RPC service, you should first call the
openwallet
method to open the wallet:
At this point, you can restart the neo-cli to enable the RPC service.
After the JSON-RPC server starts, it will monitor the following ports corresponding to the MainNet and TestNet:
For P2P and WebSocket port information, please refer to Node Introduction.
MainNet | TestNet | |
---|---|---|
JSON-RPC HTTPS | 10331 | 20331 |
JSON-RPC HTTP | 10332 | 20332 |
Command | Parameter | Description | Remark |
---|---|---|---|
getbestblockhash | Get the hash of the latest block in the main chain | ||
getblock | <hash> [verbose=0] | Return the block information with the specified hash value | |
getblock | <index> [verbose=0] | Return the block information with the specified index | |
getblockcount | Get the block count of the main chain | ||
getblockhash | <index> | Return the block hash with the specified index | |
getblockheader | <hash> [verbose=0] | Return the information of the block header with the specified script hash | |
getblockheader | <index> [verbose=0] | Return the information of the block header with the specified index | |
getblocksysfee | <index> | Return the system fees before the block with the specified index | |
getconnectioncount | Get the current connection count of the node | ||
getcontractstate | <script_hash> | Return information of the contract with the specified script hash | |
getpeers | Get a list of nodes that are currently connected/disconnected by this node | ||
getrawmempool | [shouldGetUnverified=0] | Get a list of unconfirmed transactions in memory | |
getrawtransaction | <txid> [verbose=0] | Return the transaction information with the specified hash value | |
getstorage | <script_hash> <key> | Return the value with the contract script hash and the key | |
gettransactionheight | <txid> | Return the block index in which the transaction is found. | |
getvalidators | Get the information about the validators | ||
getversion | Get the version information of the node | ||
invokefunction | <script_hash> <operation> <params> | Invoke a smart contract with the specified script hash, passing in an operation and its params | |
invokescript | <script> | Run a script through the virtual machine and returns the results | |
listplugins | Return a list of plugins loaded by the node | ||
sendrawtransaction | <hex> | Broadcast a transaction over the network. | |
submitblock | <hex> | Submit a new block to the network | Need to be a validator |
validateaddress | <address> | Verify whether the address is a valid NEO address | |
getapplicationlog | <txid> | Return the contract log based on the specified txid | |
getnep5transfers | <address> <timestamp> | Return all the NEP-5 transaction information occurred in the specified address | |
getnep5balances | <address> | Return the balance of all NEP-5 assets in the specified address |
Command | Parameter | Description | Remark |
---|---|---|---|
closewallet | Close the wallet | ||
openwallet | <address> | Open the wallet in the specified path | |
dumpprivkey | <address> | Exports the private key of the specified address | |
getbalance | <asset_id> | Returns the balance of the corresponding asset in the wallet | |
getnewaddress | Creates a new address | ||
getunclaimedgas | Gets the amount of unclaimed GAS in the wallet | ||
importprivkey | <key> | Imports the private key to the wallet | |
listaddress | Lists all the addresses in the current wallet | ||
sendfrom | <asset_id><from><to><value> | Transfer from the specified address to the destination address | |
sendmany | <outputs_array> | Initiate multiple transfers to designated addresses in a transaction | |
sendtoaddress | <asset_id><address><value> | Transfers to the specified address. |
A typical format of JSON-RPC GET request is as follows:
The following is an example of querying the block count of the main chain.
Request URL:
http://somewebsite.com:10332?jsonrpc=2.0&method=getblockcount¶ms=[]&id=1
After sending the request, you will get the following response:
{
"jsonrpc": "2.0",
"id": 1,
"result": 909129
}
A typical format of JSON-RPC Post request is as follows:
The following is an example of querying the block count of 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
}
Note: If you choose the offline package to synchronize blocks, the program may not be able to respond to the API requests. It is recommended to synchronize blocks to the latest height before using the API, otherwise, the results returned may not be the latest.
You can use the Chrome extension Postman
to facilitate the test (VPN required for installing the Chrome extension). The following is a test screenshot:
Click here to see the Chinese edition of the RPC