forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 2.7.6 cli api (neo-project#554)
* Create 2.7.6 branch for CLI API * Update cli.md (neo-project#548) * Update cli.md Revise for the new version's features. * Update cli.md Reviese for the example of request. * Update cli.md Add blank for values * Update cli.md Add blank. * Update api.md (neo-project#551) Add getvalidators API * Create getvalidators.md (neo-project#553) Add getvalidators.md * release 2.7.6
- Loading branch information
1 parent
08bf286
commit a4f19f6
Showing
68 changed files
with
5,735 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# API Reference | ||
|
||
Each node in the Neo-CLI provides an API interface for obtaining blockchain data from a node, making it easy to develop blockchain applications. The interface is provided via [JSON-RPC](http://wiki.geekdream.com/Specification/json-rpc_2.0.html), 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` | ||
|
||
To access the RPC server via HTTPS, you need to modify the configuration file config.json before starting the node and set the domain name, certificate, and password: | ||
|
||
```json | ||
{ | ||
"ApplicationConfiguration": { | ||
"Paths": { | ||
"Chain": "Chain" | ||
}, | ||
"P2P": { | ||
"Port": 10333, | ||
"WsPort": 10334 | ||
}, | ||
"RPC": { | ||
"Port": 10331, | ||
"SslCert": "YourSslCertFile.xxx", | ||
"SslCertPassword": "YourPassword" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
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](../introduction.md). | ||
|
||
| | Main Net | Test Net | | ||
| -------------- | -------- | -------- | | ||
| JSON-RPC HTTPS | 10331 | 20331 | | ||
| JSON-RPC HTTP | 10332 | 20332 | | ||
|
||
## Command List | ||
|
||
| Command | Reference | Explanation | Comments | | ||
| ----------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------ | ---------------------------- | | ||
| [dumpprivkey](api/dumpprivkey.md) | \<address> | Exports the private key of the specified address | Need to open the wallet | | ||
| [getaccountstate](api/getaccountstate.md) | \<address> | Checks account asset information according to account address | | | ||
| [getapplicationlog](api/getapplicationlog.md) | \<txid>[verbose=0] | Returns the contract log based on the specified txid. | Need to enable logging | | ||
| [getassetstate](api/getassetstate.md) | \<asset_id> | Queries asset information according to the specified asset number | | | ||
| [getbalance](api/getbalance.md) | \<asset_id> | Returns the balance of the corresponding asset in the wallet according to the specified asset number. | Need to open the wallet | | ||
| [getbestblockhash](api/getbestblockhash.md) | | Gets the hash of the tallest block in the main chain | | | ||
| [getblock](api/getblock.md) | \<hash> [verbose=0] | Returns the corresponding block information according to the specified hash value | | | ||
| [getblock](api/getblock2.md) | \<index> [verbose=0] | Returns the corresponding block information according to the specified index | | | ||
| [getblockcount](api/getblockcount.md) | | Gets the number of blocks in the main chain | | | ||
| [getblockhash](api/getblockhash.md) | \<index> | Returns the hash value of the corresponding block based on the specified index | | | ||
| [getblocksysfee](api/getblocksysfee.md) | \<index> | Returns the system fees before the block according to the specified index | | | ||
| [getconnectioncount](api/getconnectioncount.md) | | Gets the current number of connections for the node | | | ||
| [getcontractstate](api/getcontractstate.md) | \<script_hash> | Returns information about the contract based on the specified script hash | | | ||
| [getnewaddress](api/getnewaddress.md) | | Creates a new address | Need to open the wallet | | ||
| [getrawmempool](api/getrawmempool.md) | | Gets a list of unconfirmed transactions in memory | | | ||
| [getrawtransaction](api/getrawtransaction.md) | \<txid> [verbose=0] | Returns the corresponding transaction information based on the specified hash value | | | ||
| [getstorage](api/getstorage.md) | \<script_hash> \<key> | Returns the stored value based on the contract script hash and key | | | ||
| [gettxout](api/gettxout.md) | \<txid> \<n> | Returns the corresponding transaction output (change) information based on the specified hash and index | | | ||
| [getpeers](api/getpeers.md) | | Gets a list of nodes that are currently connected/disconnected by this node | | | ||
| [getversion](api/getversion.md) | | Gets version information of this node | | | ||
| [getvalidators](api/getvalidators.md) | | Gets NEO consensus nodes information | | | ||
| [invoke](api/invoke.md) | \<script_hash> \<params> | Invokes a smart contract at specified script hash with the given parameters | | | ||
| [invokefunction](api/invokefunction.md) | \<script_hash> \<operation> \<params> | Invokes a smart contract at specified script hash, passing in an operation and its params | | | ||
| [invokescript](api/invokescript.md) | \<script> | Runs a script through the virtual machine and returns the results | | | ||
| [listaddress](api/listaddress.md) | | Lists all the addresses in the current wallet. | Need to open the wallet | | ||
| [sendrawtransaction](api/sendrawtransaction.md) | \<hex> | Broadcast a transaction over the network. See the [network protocol](network-protocol.md) documentation. | | | ||
| [sendtoaddress](api/sendtoaddress.md) | \<asset_id> \<address> \<value> [fee=0] | Transfer to specified address | Need to open the wallet | | ||
| [sendmany](api/sendmany.md) | \<outputs_array> \[fee=0] \[change_address] | Bulk transfer order | Need to open the wallet | | ||
| submitblock | \<hex> | Submit new blocks | Needs to be a consensus node | | ||
| [validateaddress](api/validateaddress.md) | \<address> | Verify that the address is a correct NEO address | | | ||
|
||
## GET request example | ||
|
||
A typical JSON-RPC GET request format is as follows: | ||
|
||
The following 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¶ms=[]&id=1 | ||
``` | ||
|
||
After sending the request, you will get the following response: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": 909129 | ||
} | ||
``` | ||
|
||
## POST request example | ||
|
||
The format of a typical JSON-RPC Post request is as follows: | ||
|
||
The following is an example of how to get the number of blocks in the main chain. | ||
|
||
Request URL: | ||
|
||
``` | ||
http://somewebsite.com:10332 | ||
``` | ||
|
||
Request Body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"method": "getblockcount", | ||
"params":[], | ||
"id": 1 | ||
} | ||
``` | ||
|
||
After sending the request, you will get the following response: | ||
|
||
```json | ||
{ | ||
"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), the following is a test screenshot: | ||
|
||
![image](../../../zh-cn/node/assets/api_2.jpg) | ||
|
||
![image](../../../assets/api_3.jpg) | ||
|
||
## Other | ||
|
||
[C# JSON-RPC Command List](https://github.com/chenzhitong/CSharp-JSON-RPC/blob/master/json_rpc/Program.cs) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# dumpprivkey Method | ||
|
||
Exports the private key of the specified address. | ||
|
||
> [!Note] | ||
> You need to open the wallet in the NEO-CLI node before you execute this command. | ||
## Parameter Description | ||
|
||
Address: To export the addresses of the private key, the address is required as a standard address. | ||
|
||
## Example | ||
|
||
Request body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"method": "dumpprivkey", | ||
"params": ["ASMGHQPzZqxFB2yKmzvfv82jtKVnjhp1ES"], | ||
"id": 1 | ||
} | ||
``` | ||
|
||
Response body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": "L3FdgAisCmV******************************9XM65cvjYQ1" | ||
} | ||
``` | ||
|
||
Response Description: | ||
|
||
Returns the private key of the standard address. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# getaccountstate Method | ||
|
||
Queries the account asset information, according to the account address. | ||
|
||
## Parameter Description | ||
|
||
Account Address: A 34-bit length string beginning with A, such as AJBENSwajTzQtwyJFkiJSv7MAaaMc7DsRz. | ||
|
||
## Example | ||
|
||
Request body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"method": "getaccountstate", | ||
"params": ["AJBENSwajTzQtwyJFkiJSv7MAaaMc7DsRz"], | ||
"id": 1 | ||
} | ||
``` | ||
|
||
Response body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": { | ||
"version": 0, | ||
"script_hash": "0x1179716da2e9523d153a35fb3ad10c561b1e5b1a", | ||
"frozen": false, | ||
"votes": [], | ||
"balances": [ | ||
{ | ||
"asset": "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", | ||
"value": "94" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
Response Description: | ||
|
||
- Script_hash: Contract scipt hash; All accounts in NEO are contract accounts | ||
|
||
- Frozen: Determine if the account is frozen | ||
|
||
- Votes: Query the amount of NEO on that address used to vote | ||
|
||
- Balance: Balance of assets at the address | ||
|
||
- Asset: Asset ID | ||
|
||
- Value: Amount of Assets | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# getapplicationlog Method | ||
|
||
Returns the contract log based on the specified txid. | ||
|
||
> [!Note] | ||
> | ||
> You need to run the command `dotnet neo-cli.dll --log` to enable logging before invoking this method. The complete contract logs are stored under the ApplicationLogs directory. | ||
## Parameter Description | ||
|
||
txid:Transaction ID | ||
|
||
## Example | ||
|
||
Request body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"method": "getapplicationlog", | ||
"params": ["0x0d03ad35eb8b0bb2e43e18896d22cd2a77fe54fc0b00794fb295bcf96257d0e3"], | ||
"id": 1 | ||
} | ||
``` | ||
|
||
Response body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": { | ||
"txid": "0x0d03ad35eb8b0bb2e43e18896d22cd2a77fe54fc0b00794fb295bcf96257d0e3", | ||
"vmstate": "HALT, BREAK", | ||
"gas_consumed": "2.932", | ||
"stack": [], | ||
"notifications": [ | ||
{ | ||
"contract": "0xac116d4b8d4ca55e6b6d4ecce2192039b51cccc5", | ||
"state": { | ||
"type": "Array", | ||
"value": [ | ||
{ | ||
"type": "ByteArray", | ||
"value": "7472616e73666572" | ||
}, | ||
{ | ||
"type": "ByteArray", | ||
"value": "45fc40a091bd0de5e5408e3dbf6b023919a6f7d9" | ||
}, | ||
{ | ||
"type": "ByteArray", | ||
"value": "96da23f79685e1611b99633f7a37bf07b542d42b" | ||
}, | ||
{ | ||
"type": "ByteArray", | ||
"value": "00345cd65804" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# getassetstate Method | ||
|
||
Queries the asset information, based on the specified asset number. | ||
|
||
## Parameter Description | ||
|
||
Asset_id: Asset ID (asset identifier), which is the transaction ID of the RegistTransaction when the asset is registered. | ||
|
||
For NEO: c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b | ||
|
||
For GAS: 602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7 | ||
|
||
The remaining asset IDs can be queried through the `list asset` command in [CLI Command](../cli.md) or in the Block Chain Browser. | ||
|
||
## Example | ||
|
||
Request body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"method": "getassetstate", | ||
"params": ["c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"], | ||
"id": 1 | ||
} | ||
``` | ||
|
||
Response body: | ||
|
||
```json | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": { | ||
"version": 0, | ||
"id": "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", | ||
"type": "SystemShare", | ||
"name": [ | ||
{ | ||
"lang": "zh-CN", | ||
"name": "NEO" | ||
}, | ||
{ | ||
"lang": "en", | ||
"name": "NEO" | ||
} | ||
], | ||
"amount": "100000000", | ||
"available": "100000000", | ||
"precision": 0, | ||
"owner": "00", | ||
"admin": "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", | ||
"issuer": "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", | ||
"expiration": 2000000, | ||
"frozen": false | ||
} | ||
} | ||
``` | ||
|
Oops, something went wrong.