Back to Grin

Node API v1 Documentation

doc/api/node_api_v1.md

5.4.032.4 KB
Original Source

Node API v1 Documentation

Table of Contents

  1. Blocks Endpoint
    1. GET Blocks
  2. Headers Endpoint
    1. GET Headers
  3. Chain Endpoint
    1. GET Chain
    2. POST Chain Compact
    3. GET Chain Validate
    4. GET Chain Kernel by Commitment
    5. GET Chain Outputs by IDs
    6. GET Chain Outputs by Height
  4. Status Endpoint
    1. GET Status
  5. TxHashSet Endpoint
    1. GET TxHashSet Roots
    2. GET TxHashSet Last Outputs
    3. GET TxHashSet Last Range Proofs
    4. GET TxHashSet Last Kernels
    5. GET TxHashSet Outputs
    6. GET TxHashSet Merkle Proof
  6. Pool Endpoint
    1. GET Pool
    2. POST Pool Push
  7. Peers Endpoint
    1. POST Peers Ban
    2. POST Peers Unban
    3. GET Peers All
    4. GET Peers Connected
    5. GET Peers

Blocks Endpoint

GET Blocks

Returns data about a specific block given a hash, a height or an unspent commit.

Optionally, Merkle proofs can be excluded from the results by adding ?no_merkle_proof, rangeproofs can be included by adding ?include_proof or results can be returned as "compact blocks" by adding ?compact.

  • URL

    • /v1/blocks/hash
    • /v1/blocks/height
    • /v1/blocks/commit
  • Method:

    GET

  • URL Params

    Required: hash=[string] or height=[number] or commit=[string]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      headerobjectThe block header
      - hashstringHash of the current block
      - versionnumberVersion of the block
      - heightnumberHeight of this block since the genesis block (height 0)
      - previousstringHash of the block previous to this in the chain
      - prev_rootstringRoot hash of the header MMR at the previous header
      - timestampstringRFC3339 timestamp at which the block was built
      - output_rootstringMerklish root of all the commitments in the TxHashSet
      - range_proof_rootstringMerklish root of all range proofs in the TxHashSet
      - kernel_rootstringMerklish root of all transaction kernels in the TxHashSet
      - noncenumberNonce increment used to mine this block
      - edge_bitsnumberSize of the cuckoo graph (2_log of number of edges)
      - cuckoo_solution[]numberThe Cuckoo solution for this block
      - total_difficultynumberTotal accumulated difficulty since genesis block
      - secondary_scalingnumberVariable difficulty scaling factor for secondary proof of work
      - total_kernel_offsetstringTotal kernel offset since genesis block
      inputs[]stringInput transactions
      outputs[]objectOutputs transactions
      - output_typestringThe type of output Coinbase
      - commitstringThe homomorphic commitment representing the output's amount (as hex string)
      - spentboolWhether the output has been spent
      - proofstringRangeproof (as hex string)
      - proof_hashstringRangeproof hash (as hex string)
      - block_heightnumberBlock height at which the output is found
      - merkle_proofstringMerkle proof
      kernels[]objectTransaction Kernels (a proof that a transaction sums to zero)
      - featuresobjectOptions for a kernel's structure or use
      - bitsnumberRepresentation of the features in bits
      - feenumberFee originally included in the transaction this proof is for
      - lock_heightnumberThe max lock_height of all inputs to this transaction
      - excess[]numberRemainder of the sum of all transaction commitments
      - excess_sig[]numberThe signature proving the excess is a valid public key (signs the tx fee)
  • Error Response:

    • Code: 404 or 500
    • Content: failed to parse input: Not found.
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/blocks/1",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

Headers Endpoint

GET Headers

Returns data about a block headers given either a hash or height or an output commit.

  • URL

    • /v1/headers/hash
    • /v1/headers/height
    • /v1/headers/commit
  • Method:

    GET

  • URL Params

    Required: hash=[string] or height=[number] or commit=[string]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      headerobjectThe block header
      - hashstringHash of the current block
      - versionnumberVersion of the block
      - heightnumberHeight of this block since the genesis block (height 0)
      - previousstringHash of the block previous to this in the chain
      - prev_rootstringRoot hash of the header MMR at the previous header
      - timestampstringRFC3339 timestamp at which the block was built
      - output_rootstringMerklish root of all the commitments in the TxHashSet
      - range_proof_rootstringMerklish root of all range proofs in the TxHashSet
      - kernel_rootstringMerklish root of all transaction kernels in the TxHashSet
      - noncenumberNonce increment used to mine this block
      - edge_bitsnumberSize of the cuckoo graph (2_log of number of edges)
      - cuckoo_solution[]numberThe Cuckoo solution for this block
      - total_difficultynumberTotal accumulated difficulty since genesis block
      - total_kernel_offsetstringTotal kernel offset since genesis block
  • Error Response:

    • Code: 404 or 500
    • Content: failed to parse input: Not found.
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/headers/1",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

Chain Endpoint

GET Chain

Retrieves details about the state of the current fork tip.

  • URL

    /v1/chain

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      heightnumberHeight of the tip (max height of the fork)
      last_block_pushedstringLast block pushed to the fork
      prev_block_to_laststringBlock previous to last
      total_difficultynumberTotal difficulty accumulated on that fork since genesis block
  • Error Response:

    • Code: 404 or 500
    • Content: failed to parse input: Not found.
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/chain",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

POST Chain Compact

Trigger a compaction of the chain state to regain storage space.

  • URL

    /v1/chain/compact

  • Method:

    POST

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/chain/compact",
        dataType: "json",
        type : "POST",
        success : function(r) {
          console.log(r);
        }
      });
    

GET Chain Validate

Trigger a validation of the chain state.

  • URL

    /v1/chain/validate

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/chain/validate",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET Chain Kernel By Commitment

Look up an on-chain kernel and the height of the block it is included in. By default min_height is 0.

  • URL

    • /v1/chain/kernels/xxx?min_height=yyy&max_height=zzz
  • Method:

    GET

  • URL Params

    Required: commitment=[string]

    Optional: min_height=[number] max_height=[number]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      tx_kernelobjectTransaction Kernel
      - featuresobjectThe type of output Coinbase
      - featuresobjectThe kernel features. Can either be Plain, Coinbase or HeightLocked.
      - excessstringThe kernel excess also called commitment
      - excess_sigstringThe excess signature
      heightstringTHe height of the block this kernel is included in
      mmr_heightstringPosition in the MMR
  • Error Response:

    • Code: 404 or 500
    • Content: []
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/chain/kernels/0939fe3dc6a35350da91c6288138b7a257e0c0322eae30bda3938229d649e2e642?max_height=324300",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET Chain Outputs By IDs

Retrieves details about specifics outputs. Supports retrieval of multiple outputs in a single request.

  • URL

    • /v1/chain/outputs/byids?id=x
    • /v1/chain/outputs/byids?id=x,y,z
    • /v1/chain/outputs/byids?id=x&id=y&id=z
  • Method:

    GET

  • URL Params

    Required: id=[string]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      outputs[]objectOutputs
      - output_typestringThe type of output Coinbase
      - commitstringThe homomorphic commitment representing the output's amount (as hex string)
      - spentboolWhether the output has been spent
      - proofstringRangeproof (as hex string)
      - proof_hashstringRangeproof hash (as hex string)
      - block_heightnumberBlock height at which the output is found
      - merkle_proofstringMerkle proof
  • Error Response:

    • Code: 404 or 500
    • Content: []
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/chain/outputs/byids?id=0803516094a30830ed9fedff1c63251b51703ddffbb73f944d9e33e8fa5d17444f",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET Chain Outputs By Height

Retrieves details about specifics outputs. Supports retrieval of multiple outputs in a single request.

  • URL

    /v1/chain/outputs/byheight?start_height=x&end_height=y

  • Method:

    GET

  • URL Params

    Required: start_height=[number] end_height=[number]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      headerobjectThe block header
      - hashstringHash of the current block
      - heightnumberHeight of this block since the genesis block (height 0)
      - previousstringHash of the block previous to this in the chain
      outputs[]objectOutputs
      - output_typestringThe type of output Coinbase
      - commitstringThe homomorphic commitment representing the output's amount (as hex string)
      - spentboolWhether the output has been spent
      - proofstringRangeproof (as hex string)
      - proof_hashstringRangeproof hash (as hex string)
      - block_heightnumberBlock height at which the output is found
      - merkle_proofstringMerkle proof
  • Error Response:

    • Code: 404 or 500
    • Content: []
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/chain/outputs/byheight?start_height=101&end_height=200",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

Status Endpoint

GET Status

Returns various information about the node and the network

  • URL

    /v1/status

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      protocol_versionnumberThe node protocol version
      user_agentnumberThe node user agent
      connectionsnumberThe current number of connections
      tipobjectThe state of the current fork tip
      heightnumberHeight of the tip (max height of the fork)
      last_block_pushedstringLast block pushed to the fork
      prev_block_to_laststringBlock previous to last
      total_difficultynumberTotal difficulty accumulated on that fork since genesis block
      sync_statusstringThe current sync status
      sync_infoobjectAdditional sync information. This field is optional.
  • Error Response:

    • Code: 404 or 500
    • Content: failed to parse input: Not found.
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/stats",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

TxHashSet Endpoint

GET TxHashSet Roots

Retrieve the roots of the TxHashSet

  • URL

    /v1/txhashset/roots

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      output_root_hashstringOutput root hash
      range_proof_root_hashstringRangeproof root hash
      kernel_root_hashstringKernel set root hash
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/txhashset/roots",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET TxHashSet Last Outputs

Retrieves the last n outputs inserted into the tree.

  • URL

    • /v1/txhashset/lastoutputs (gets last 10)
    • /v1/txhashset/lastoutputs?n=x
  • Method:

    GET

  • URL Params

    Required: n=[number]

  • Data Params

    None

  • Success Response:

    • Code: 200
    • Content:

    Array of

    FieldTypeDescription
    hashstringhash of the outputs
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/txhashset/lastoutputs?n=20",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET TxHashSet Last Range Proofs

Retrieves the last n rangeproofs inserted in to the tree.

  • URL

    • /v1/txhashset/lastrangeproofs (gets last 10)
    • /v1/txhashset/lastrangeproofs?n=x
  • Method:

    GET

  • URL Params

    Required: n=[number]

  • Data Params

    None

  • Success Response:

    • Code: 200
    • Content:

    Array of

    FieldTypeDescription
    hashstringhash of the rangeproofs
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "v1/txhashset/lastrangeproofs",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET TxHashSet Last Kernels

Retrieves the last n kernels inserted in to the tree.

  • URL

    • /v1/txhashset/lastkernels (gets last 10)
    • /v1/txhashset/lastkernels?n=x
  • Method:

    GET

  • URL Params

    Required: n=[number]

  • Data Params

    None

  • Success Response:

    • Code: 200
    • Content:

    Array of

    FieldTypeDescription
    hashstringhash of the kernels
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/txhashset/lastkernels?n=20",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET TxHashSet Outputs

UTXO traversal. Retrieves last utxos since a start index until a max.

  • URL

    /v1/txhashset/outputs?start_index=x&max=y

  • Method:

    GET

  • URL Params

    Required: start_index=[number] max=[number]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      highest_indexnumberThe last available output index
      last_retrieved_indexnumberThe last insertion index retrieved
      outputs[]objectOutputs
      - output_typestringThe type of output Coinbase
      - commitstringThe homomorphic commitment representing the output's amount (as hex string)
      - spentboolWhether the output has been spent
      - proofstringRangeproof (as hex string)
      - proof_hashstringRangeproof hash (as hex string)
      - block_heightnumberBlock height at which the output is found
      - merkle_proofstringMerkle proof
      kernels[]objectTransaction Kernels (a proof that a transaction sums to zero)
      - featuresobjectOptions for a kernel's structure or use
      - bitsnumberRepresentation of the features in bits
      - feenumberFee originally included in the transaction this proof is for
      - lock_heightnumberThe max lock_height of all inputs to this transaction
      - excess[]numberRemainder of the sum of all transaction commitments
      - excess_sig[]numberThe signature proving the excess is a valid public key (signs the tx fee)
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/txhashset/outputs?start_index=1&max=100",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET TxHashSet Merkle Proof

Build a merkle proof for a given output id and return a dummy output with merkle proof for position filled out.

  • URL

    /v1/txhashset/merkleproof?id=x

  • Method:

    GET

  • URL Params

    Required: id=[string]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      outputs[]objectOutputs
      - output_typestringThe type of output Coinbase
      - commitstringThe homomorphic commitment representing the output's amount (as hex string)
      - spentboolWhether the output has been spent
      - proofstringRangeproof (as hex string)
      - proof_hashstringRangeproof hash (as hex string)
      - block_heightnumberBlock height at which the output is found
      - merkle_proofstringMerkle proof
  • Error Response:

    • Code: 404 or 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/txhashset/merkleproof?id=0803516094a30830ed9fedff1c63251b51703ddffbb73f944d9e33e8fa5d17444f",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

Pool Endpoint

GET Pool

Retrieves basic information about the transaction pool.

  • URL

    /v1/pool

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      pool_sizenumberNumber of transactions in the memory pool
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/pool",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

POST Pool Push

Push new transaction to our local transaction pool. Add ?fluff at the end of the URL to bypass Dandelion relay.

  • URL

    /v1/pool/push

  • Method:

    POST

  • URL Params

    None

  • Data Params

    file=[string] (hex encoded transaction)

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/pool/push",
        dataType: "json",
        type : "POST",
        data: {
          file: tx
        },
        success : function(r) {
          console.log(r);
        }
      });
    

Peers Endpoint

POST Peers Ban

Ban a specific peer.

  • URL

    /v1/peers/a.b.c.d:p/ban

  • Method:

    POST

  • URL Params

    a.b.c.d:p=[string]

  • Data Params

    None

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 400
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/peers/192.168.1.1:13414/ban",
        dataType: "json",
        type : "POST",
        success : function(r) {
          console.log(r);
        }
      });
    

POST Peers Unban

Unban a specific peer.

  • URL

    /v1/a.b.c.d:p/unban

  • Method:

    POST

  • URL Params

    a.b.c.d:p=[string]

  • Data Params

    None

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 400
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/192.168.1.1:13414/unban",
        dataType: "json",
        type : "POST",
        success : function(r) {
          console.log(r);
        }
      });
    

GET Peers All

Retrieves all peers in db.

  • URL

    /v1/peers/all

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
    • Content:

    Array of

    FieldTypeDescription
    addrstringNetwork address of the peer
    capabilitiesobjectWhat capabilities the peer advertises
    - bitsnumberRepresentation of the capabilities in bits
    user_agentstringThe peer user agent
    flagsstringState the peer has been detected with.
    last_bannednumberThe time the peer was last banned
    ban_reasonstringThe reason for the ban
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/peers/all",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET Peers Connected

Retrieves all connected peers

  • URL

    /v1/peers/connected

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
    • Content:

    Array of

    FieldTypeDescription
    capabilitiesobjectWhat capabilities the peer advertises
    - bitsnumberRepresentation of the capabilities in bits
    user_agentstringThe peer user agent
    versionnumberSoftware version of the peer
    addrstringNetwork address of the peer
    total_difficultynumberTotal of difficulty of the peer
    heightnumberHeight of the peer
    directionstringDirection of the connection (Inbound
  • Error Response:

    • Code: 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/peers/connected",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });
    

GET Peers

Retrieves information about a specific peer.

  • URL

    /v1/peers/a.b.c.d

  • Method:

    GET

  • URL Params

    a.b.c.d=[string]

  • Data Params

    None

  • Success Response:

    • Code: 200

    • Content:

      FieldTypeDescription
      addrstringNetwork address of the peer
      capabilitiesobjectWhat capabilities the peer advertises
      - bitsnumberRepresentation of the capabilities in bits
      user_agentstringThe peer user agent
      flagsstringState the peer has been detected with.
      last_bannednumberThe time the peer was last banned
      ban_reasonstringThe reason for the ban
  • Error Response:

    • Code: 404 or 500
  • Sample Call:

    javascript
      $.ajax({
        url: "/v1/peers/192.168.1.2",
        dataType: "json",
        type : "GET",
        success : function(r) {
          console.log(r);
        }
      });