2019-09-18 07:55:39 +00:00
# RPC
## Client
Client is provided as a Go package, so please refer to the
[relevant godocs page ](https://godoc.org/github.com/nspcc-dev/neo-go/pkg/rpc ).
## Server
The server is written to support as much of the [JSON-RPC 2.0 Spec ](http://www.jsonrpc.org/specification ) as possible. The server is run as part of the node currently.
### Example call
An example would be viewing the version of the node:
```bash
$ curl -X POST -d '{"jsonrpc": "2.0", "method": "getversion", "params": [], "id": 1}' http://localhost:20332
```
which would yield the response:
```json
{
2021-09-06 15:40:41 +00:00
"result" : {
"useragent" : "/NEO-GO:0.97.2/",
"tcpport" : 10333,
"network" : 860833102,
"nonce" : 105745208
},
2019-09-18 07:55:39 +00:00
"jsonrpc" : "2.0",
2021-09-06 15:40:41 +00:00
"id" : 1
2019-09-18 07:55:39 +00:00
}
```
### Supported methods
2020-03-06 17:38:17 +00:00
| Method |
| ------- |
2021-04-08 12:15:29 +00:00
| `calculatenetworkfee` |
2021-10-07 13:56:27 +00:00
| `findstates` |
2020-03-06 17:38:17 +00:00
| `getapplicationlog` |
| `getbestblockhash` |
| `getblock` |
| `getblockcount` |
| `getblockhash` |
| `getblockheader` |
2021-02-07 19:01:22 +00:00
| `getblockheadercount` |
2022-07-01 13:02:03 +00:00
| `getcandidates` |
2021-03-18 21:11:38 +00:00
| `getcommittee` |
2020-03-06 17:38:17 +00:00
| `getconnectioncount` |
| `getcontractstate` |
2021-03-18 21:11:38 +00:00
| `getnativecontracts` |
2021-11-17 20:04:50 +00:00
| `getnep11balances` |
| `getnep11properties` |
| `getnep11transfers` |
2020-11-24 08:14:25 +00:00
| `getnep17balances` |
| `getnep17transfers` |
2021-03-18 21:11:38 +00:00
| `getnextblockvalidators` |
2020-03-06 17:38:17 +00:00
| `getpeers` |
2021-03-18 21:11:38 +00:00
| `getproof` |
2020-03-06 17:38:17 +00:00
| `getrawmempool` |
| `getrawtransaction` |
2021-10-07 09:03:37 +00:00
| `getstate` |
2021-03-18 21:11:38 +00:00
| `getstateheight` |
| `getstateroot` |
2020-03-06 17:38:17 +00:00
| `getstorage` |
| `gettransactionheight` |
2020-06-01 20:27:03 +00:00
| `getunclaimedgas` |
2020-03-06 17:38:17 +00:00
| `getversion` |
2021-03-18 21:11:38 +00:00
| `invokecontractverify` |
2020-03-06 17:38:17 +00:00
| `invokefunction` |
| `invokescript` |
| `sendrawtransaction` |
| `submitblock` |
2021-03-18 21:11:38 +00:00
| `submitoracleresponse` |
2022-06-15 18:23:29 +00:00
| `terminatesession` |
| `traverseiterator` |
2020-03-06 17:38:17 +00:00
| `validateaddress` |
2021-03-18 21:11:38 +00:00
| `verifyproof` |
2019-09-18 07:55:39 +00:00
2020-05-18 22:01:35 +00:00
#### Implementation notices
2022-07-01 15:44:59 +00:00
##### JSON representation of enumerations
C# implementation contains a number of enumerations and while it outputs them
into JSON as comma-separated strings (or just strings if only one value is
allowed for this type) it accepts pure numbers for input (see #2563 for
example). NeoGo currently doesn't support this behavior. This affects the
following data types:
* transaction attribute type
* oracle response code
* transaction witness scope
* rule witness action
* condition rule witness type
* function call flag
* function call parameter type
* execution trigger type
* stack item type
Any call that takes any of these types for input in JSON format is affected.
2021-03-18 21:11:38 +00:00
##### `invokefunction`
2020-05-18 22:01:35 +00:00
2022-04-20 18:30:09 +00:00
neo-go implementation of `invokefunction` does not return `tx`
2020-05-18 22:01:35 +00:00
field in the answer because that requires signing the transaction with some
2022-04-20 18:30:09 +00:00
key in the server, which doesn't fit the model of our node-client interactions.
If this signature is lacking, the transaction is almost useless, so there is no point
2020-05-18 22:01:35 +00:00
in returning it.
2022-04-20 18:30:09 +00:00
It's possible to use `invokefunction` not only with a contract scripthash, but also
with a contract name (for native contracts) or a contract ID (for all contracts). This
2020-09-25 15:43:47 +00:00
feature is not supported by the C# node.
2020-09-25 09:40:57 +00:00
##### `getcontractstate`
It's possible to get non-native contract state by its ID, unlike with C# node where
it only works for native contracts.
2021-09-09 13:31:23 +00:00
##### `getrawtransaction`
2022-04-20 18:30:09 +00:00
VM state is included into verbose response along with other transaction fields if
2021-09-09 13:31:23 +00:00
the transaction is already on chain.
2021-10-29 14:06:45 +00:00
##### `getstateroot`
This method is able to accept state root hash instead of index, unlike the C# node
where only index is accepted.
2021-02-03 20:09:52 +00:00
##### `getstorage`
This method doesn't work for the Ledger contract, you can get data via regular
2021-10-29 14:06:45 +00:00
`getblock` and `getrawtransaction` calls. This method is able to get storage of
2022-04-20 18:30:09 +00:00
a native contract by its name (case-insensitive), unlike the C# node where
2021-10-29 14:06:45 +00:00
it only possible for index or hash.
2021-02-03 20:09:52 +00:00
2022-07-01 15:22:16 +00:00
##### `getnep11balances` and `getnep17balances`
2022-04-20 18:30:09 +00:00
neo-go implementation of `getnep11balances` and `getnep17balances` does not
2021-11-17 20:04:50 +00:00
perform tracking of NEP-11 and NEP-17 balances for each account as it is done
2022-04-20 18:30:09 +00:00
in the C# node. Instead, a neo-go node maintains a list of standard-compliant
2021-11-17 20:04:50 +00:00
contracts, i.e. those contracts that have `NEP-11` or `NEP-17` declared in the
supported standards section of the manifest. Each time balances are queried,
2022-04-20 18:30:09 +00:00
the neo-go node asks every NEP-11/NEP-17 contract for the account balance by
2021-11-17 20:04:50 +00:00
invoking `balanceOf` method with the corresponding args. Invocation GAS limit
is set to be 3 GAS. All non-zero balances are included in the RPC call result.
2022-04-20 18:30:09 +00:00
Thus, if a token contract doesn't have proper standard declared in the list of
2021-11-17 20:04:50 +00:00
supported standards but emits compliant NEP-11/NEP-17 `Transfer`
notifications, the token balance won't be shown in the list of balances
returned by the neo-go node (unlike the C# node behavior). However, transfer
logs of such tokens are still available via respective `getnepXXtransfers` RPC
calls.
2021-07-25 12:00:44 +00:00
2022-04-20 18:30:09 +00:00
The behavior of the `LastUpdatedBlock` tracking for archival nodes as far as for
2021-08-11 11:29:03 +00:00
governing token balances matches the C# node's one. For non-archival nodes and
2022-04-20 18:30:09 +00:00
other NEP-11/NEP-17 tokens, if transfer's `LastUpdatedBlock` is lower than the
latest state synchronization point P the node working against,
2021-11-17 20:04:50 +00:00
`LastUpdatedBlock` equals P. For NEP-11 NFTs `LastUpdatedBlock` is equal for
all tokens of the same asset.
2022-07-01 15:22:16 +00:00
##### `getnep11transfers` and `getnep17transfers`
2021-11-17 20:04:50 +00:00
`transfernotifyindex` is not tracked by NeoGo, thus this field is always zero.
2021-07-25 12:00:44 +00:00
2020-03-03 15:15:26 +00:00
### Unsupported methods
2022-04-20 18:30:09 +00:00
Methods listed below are not going to be supported for various reasons
2020-03-03 15:15:26 +00:00
and we're not accepting issues related to them.
| Method | Reason |
| ------- | ------------|
2021-03-18 21:11:38 +00:00
| `closewallet` | Doesn't fit neo-go wallet model |
| `dumpprivkey` | Shouldn't exist for security reasons, see `closewallet` comment also |
| `getnewaddress` | See `closewallet` comment, use CLI to do that |
| `getwalletbalance` | See `closewallet` comment, use `getnep17balances` for that |
| `getwalletunclaimedgas` | See `closewallet` comment, use `getunclaimedgas` for that |
| `importprivkey` | Not applicable to neo-go, see `closewallet` comment |
| `listaddress` | Not applicable to neo-go, see `closewallet` comment |
2020-03-03 15:15:26 +00:00
| `listplugins` | neo-go doesn't have any plugins, so it makes no sense |
2021-03-18 21:11:38 +00:00
| `openwallet` | Doesn't fit neo-go wallet model |
| `sendfrom` | Not applicable to neo-go, see `openwallet` comment |
| `sendmany` | Not applicable to neo-go, see `openwallet` comment |
2020-03-03 15:15:26 +00:00
| `sendtoaddress` | Not applicable to neo-go, see `claimgas` comment |
2020-05-18 22:01:35 +00:00
### Extensions
2019-11-26 10:13:17 +00:00
2020-05-18 22:01:35 +00:00
Some additional extensions are implemented as a part of this RPC server.
2019-11-26 10:13:17 +00:00
2021-03-18 21:11:38 +00:00
#### `getblocksysfee` call
This method returns cumulative system fee for all transactions included in a
block. It can be removed in future versions, but at the moment you can use it
2022-04-20 18:30:09 +00:00
to see how much GAS is burned with a particular block (because system fees are
2021-03-18 21:11:38 +00:00
burned).
2022-04-07 15:13:08 +00:00
#### `invokecontractverifyhistoric`, `invokefunctionhistoric` and `invokescripthistoric` calls
These methods provide the ability of *historical* calls and accept block hash or
block index or stateroot hash as the first parameter and the list of parameters
that is the same as of `invokecontractverify` , `invokefunction` and
`invokescript` correspondingly. The historical call assumes that the contracts'
2022-06-20 15:25:45 +00:00
storage state has all its values got from MPT with the specified stateroot (or,
which is the same, with the stateroot of the block of the specified height) and
the transaction will be invoked using interop context with block which is next to
the block with the specified height. This allows to perform test invocation using
the specified past chain state. These methods may be useful for debugging
purposes.
2022-04-07 15:13:08 +00:00
Behavior note: any historical RPC call need the historical chain state to be
presented in the node storage, thus if the node keeps only latest MPT state
the historical call can not be handled properly.The historical calls only
guaranteed to correctly work on archival node that stores all MPT data. If a
node keeps the number of latest states and has the GC on (this setting
corresponds to the `RemoveUntraceableBlocks` set to `true` ), then the behaviour
of historical RPC call is undefined. GC can always kick some data out of the
storage while the historical call is executing, thus keep in mind that the call
can be processed with `RemoveUntraceableBlocks` only with limitations on
available data.
2021-03-18 21:11:38 +00:00
#### `submitnotaryrequest` call
This method can be used on P2P Notary enabled networks to submit new notary
payloads to be relayed from RPC to P2P.
2021-11-17 20:04:50 +00:00
#### Limits and paging for getnep11transfers and getnep17transfers
2020-09-14 19:35:41 +00:00
2021-11-17 20:04:50 +00:00
`getnep11transfers` and `getnep17transfers` RPC calls never return more than
2022-04-20 18:30:09 +00:00
1000 results for one request (within the specified time frame). You can pass your
2021-11-17 20:04:50 +00:00
own limit via an additional parameter and then use paging to request the next
batch of transfers.
2020-09-14 19:35:41 +00:00
2022-04-20 18:30:09 +00:00
An example of requesting 10 events for address NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc
2021-10-11 13:56:20 +00:00
within 0-1600094189000 timestamps:
2020-09-14 19:35:41 +00:00
```json
2020-11-24 08:14:25 +00:00
{ "jsonrpc": "2.0", "id": 5, "method": "getnep17transfers", "params":
2021-10-11 13:56:20 +00:00
["NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", 0, 1600094189000, 10] }
2020-09-14 19:35:41 +00:00
```
Get the next 10 transfers for the same account within the same time frame:
```json
2020-11-24 08:14:25 +00:00
{ "jsonrpc": "2.0", "id": 5, "method": "getnep17transfers", "params":
2021-10-11 13:56:20 +00:00
["NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", 0, 1600094189000, 10, 1] }
2020-09-14 19:35:41 +00:00
```
2020-05-18 22:01:35 +00:00
#### Websocket server
2019-11-28 16:08:31 +00:00
2020-05-18 22:01:35 +00:00
This server accepts websocket connections on `ws://$BASE_URL/ws` address. You
can use it to perform regular RPC calls over websockets (it's supposed to be a
little faster than going regular HTTP route) and you can also use it for
additional functionality provided only via websockets (like notifications).
#### Notification subsystem
Notification subsystem consists of two additional RPC methods (`subscribe` and
`unsubscribe` working only over websocket connection) that allow to subscribe
to various blockchain events (with simple event filtering) and receive them on
the client as JSON-RPC notifications. More details on that are written in the
[notifications specification ](notifications.md ).
2019-11-26 10:13:17 +00:00
2019-09-18 07:55:39 +00:00
## Reference
* [JSON-RPC 2.0 Specification ](http://www.jsonrpc.org/specification )
2020-02-15 16:26:47 +00:00
* [NEO JSON-RPC 2.0 docs ](https://docs.neo.org/docs/en-us/reference/rpc/latest-version/api.html )