-
UPDATE
- Invocation Style: getblockheader,getrawmempool
- Returns: getblock,getblockheader,getrawtransaction,getversion,getcontractstate
-
DELETE
- Discard the following commands:
claimgas
,dumpprivkey
,getaccountstate
,getapplicationlog
,getassetstate
,getbalance
,getclaimable
,getmetricblocktimestamp
,getnep5balances
,getnep5transfers
,getnewaddress
,gettxout
,getunclaimed
,getunclaimedgas
,getunspents
,getwalletheight
,importprivkey
,invoke
,listaddress
,sendfrom
,sendtoaddress
,sendmany
- 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 start a node that provides the RPC service:
dotnet neo-cli.dll /rpc
-
HTTPS: To access the RPC server via HTTPS, you need to set the domain name, certificate and password in the configuration file
config.json
before starting a node :{ "ApplicationConfiguration": { "Paths": { "Chain": "Chain" }, "P2P": { "Port": 10333, "WsPort": 10334 }, "RPC": { "Port": 10331, "SslCert": "YourSslCertFile.xxx", "SslCertPassword": "YourPassword" } } }
-
Open wallet by default: If set to open wallet automatically when launching neo-cli, you also need to make the following changes in
config.json
before starting a node:- Change the attribute
IsActive
of the objectUnlockWallet
totrue
. - Specify the file name and password of the desired wallet.
... "UnlockWallet": { "Path": "YourWallet.json", "Password": "YourPassword", "StartConsensus": false, "IsActive": true } ...
- Change the attribute
At this point, on the condition of the NEO-CLI launched, the client will automatically open the specified wallet and download the wallet index after the full block synchronization.
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 | |
<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 | |
<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 |
Command | Parameter | Description | Remark |
---|---|---|---|
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