Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (52 sloc) 2.33 KB

Accessing NEO API with RPC

中文版

When running a NEO node with NEO CLI, the node can provide an API interface for obtaining blockchain data from the node, making it easy to develop blockchain applications. The interface is provided via JSON-RPC, and the underlying protocol uses HTTP/HTTPS for communication. This guide will go through the steps of runing a CLI node with RPC and sending an API call using Postman.

Requirements

  • NEO CLI
  • Postman (Or any other RPC program)
  • Windows / Linux system (NEO CLI only supports these systems)

Procedures

  1. If you are accessing RPC using HTTP, skip to step 1. If you are using HTTPS, open config.json in the NEO-CLI directory. Change the Values for "RPC" into:

    "RPC": {
      "Port": 10331,
      "SslCert": "YourSslCertFile.xxx",
      "SslCertPassword": "YourPassword"
    }

    Reference the table below for the value of"Port"

     

    Main Net Test Net
    JSON-RPC HTTPS 10331 20331
    JSON-RPC HTTP 10332 20332

    Table 1

 

  1. In command lines, navigate to the NEO-CLI directory.

  2. Launch NEO CLI with RPC using the following command

    dotnet neo-cli.dll --rpc

    After ensuring that the node is running and synced to the latest block, proceed to Postman

  3. Create a new request, set the request type to POST

    img

    Enter the request URL

    http://localhost:{port}
    

    {port} is the value of your RPC port in config.json. See Table 1.

    Enter request body as a json file:

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

    As shown in the picture, the example calls a getblockcount method.

    img

  4. Send the request, if you get a return like this, the request is successful.

    img


Relevant resources: Reference for all API methods