Installation and usage of the platform

REST API: information about smart contracts

https://img.shields.io/badge/auth-required-orange.svg

A set of methods from the contracts group is provided to obtain information about smart contracts loaded on the network.

GET /contracts

The method returns information on all smart contracts uploaded to the network. For each smart contract, the following parameters are returned in the response:

  • contract_id – smart contract identifier;

  • image – name of the Docker image of the smart contract, or its absolute path in the repository;

  • imageHash – hash sum of the smart contract;

  • version – smart contract version;

  • active – smart contract status at the time of sending the query:

    • true – running;

    • false – not running.

Response example for one smart contract:

GET /contracts:
[
  {
    "contractId": "dmLT1ippM7tmfSC8u9P4wU6sBgHXGYy6JYxCq1CCh8i",
    "image": "registry.wvservices.com/wv-sc/may14_1:latest",
    "imageHash": "ff9b8af966b4c84e66d3847a514e65f55b2c1f63afcd8b708b9948a814cb8957",
    "version": 1,
    "active": false
   }
 ]

POST /contracts

The method returns a set of “key:value” fields written to the stack of one or more smart contracts. The IDs of the requested smart contracts are specified in the contracts field of the request.

Response example for one smart contract:

POST /contracts:
{
  "8vBJhy4eS8oEwCHC3yS3M6nZd5CLBa6XNt4Nk3yEEExG": [
   {
   "type": "string",
   "value": "Only description",
   "key": "Description"
   },
   {
   "type": "integer",
   "value": -9223372036854776000,
   "key": "key_may"
   }
  ]
 }

GET /contracts/status/{id}

The method returns the status of executed transaction 103 to create a smart contract by transaction identifier {id}. However, if the node is restarted after sending the transaction to the blockchain, the method will not return the correct status of that transaction.

Parameters returned in the method response:

  • sender – transaction sender address;

  • senderPublicKey – the public key of the transaction sender;

  • txId – transaction identifier;

  • status – transaction status: successfully hit the block, confirmed, rejected;

  • code – error code (if any);

  • message – message about the status of the transaction;

  • timestamp – the Unix Timestamp (in milliseconds);

  • signature – transaction signature.

Response example:

GET /contracts/status/{id}:
{
  "sender": "3GLWx8yUFcNSL3DER8kZyE4TpyAyNiEYsKG",
  "senderPublicKey": "4WnvQPit2Di1iYXDgDcXnJZ5yroKW54vauNoxdNeMi2g",
  "txId": "4q5Q8vLeGBpcdQofZikyrrjHUS4pB1AB4qNEn2yHRKWU",
  "status": "Success",
  "code": null,
  "message": "Smart contract transaction successfully mined",
  "timestamp": 1558961372834,
  "signature": "4gXy7qtzkaHHH6NkksnZ5pnv8juF65MvjQ9JgVztpgNwLNwuyyr27Db3gCh5YyADqZeBH72EyAkBouUoKvwJ3RQJ"
 }

GET /contracts/{contractId}

The method returns the result of smart contract execution by its {contractId} identifier.

Response example:

GET /contracts/{contractId}:
[
  {
    "key": "avg",
    "type": "string",
    "value": "3897.80146957"
  },
  {
    "key": "buy_price",
    "type": "string",
    "value": "3842"
  }
]

POST /contracts/{contractId}

The method returns key values from the {contractId} smart contract state. The query specifies the following data:

  • contract_id – smart contract identifier;

  • limit – the limit of number of data blocks to be obtained;

  • offset – number of data blocks to be missed in the method response;

  • matches – an optional parameter to compose a regular expression that filters the keys.

Response example:

POST /contracts/{contractId}:
[
  {
    "type": "string",
    "key": "avg",
    "value": "3897.80146957"
  },
  {
    "type": "string",
    "key": "buy_price",
    "value": "3842"
  }
]

GET /contracts/executed-tx-for/{id}

The method returns the result of smart contract execution by identifier of a transaction 105.

The method’s response returns transaction data 105, as well as the results of the execution in the results field.

Response example if a smart contract has not been executed:

GET /contracts/executed-tx-for/{id}:
{
  "type": 105,
  "id": "2UAHvs4KsfBbRVPm2dCigWtqUHuaNQou83CXy6DGDiRa",
  "sender": "3PKyW5FSn4fmdrLcUnDMRHVyoDBxybRgP58",
  "senderPublicKey": "2YvzcVLrqLCqouVrFZynjfotEuPNV9GrdauNpgdWXLsq",
  "fee": 500000,
  "timestamp": 1549365523980,
  "proofs": [
    "4BoG6wQnYyZWyUKzAwh5n1184tsEWUqUTWmXMExvvCU95xgk4UFB8iCnHJ4GhvJm86REB69hKM7s2WLAwTSXquAs"
  ],
  "version": 1,
  "tx": {
      "type": 103,
      "id": "ULcq9R7PvUB2yPMrmBdxoTi3bcRmQPT3JDLLLZVj4Ky",
      "sender": "3N3YTj1tNwn8XUJ8ptGKbPuEFNa9GFnhqew",
      "senderPublicKey": "3kW7vy6nPC59BXM67n5N56rhhAv38Dws5skqDsjMVT2M",
      "fee": 500000,
      "timestamp": 1550591678479,
      "proofs": [ "yecRFZm9iBLyDy93bDVaNo1PR5Qkkic7196GAgUt9TNH1cnQphq4yGQQ8Fxj4BYA4TaqYVw5qxtWzGMPQyVeKYv" ],
      "version": 1,
      "image": "stateful-increment-contract:latest",
      "imageHash": "7d3b915c82930dd79591aab040657338f64e5d8b842abe2d73d5c8f828584b65",
      "contractName": "stateful-increment-contract",
      "params": [],
      "height": 1619
  },
  "results": []
}

GET /contracts/{contractId}/{key}

Returns the {key} value of the executed smart contract by its identifier.

Response example:

GET /contracts/{contractId}/{key}:
{
  "key": "updated",
  "type": "integer",
  "value": 1545835909
}
See also