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 executable 103. CreateContract transaction or another contract call transaction (Call, Update) 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;

  • contract_id – smart contract call identifier;

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

    • 0 – successfully executed (SUCCESS);

    • 1 – business error, the contract is not executed, the call is rejected (ERROR);

    • 2 – system error during the execution of the smart contract (FAILURE).

  • code – code of an error that occurred during the smart contract execution (if any);

  • message – transaction status message; contains additional information about the status specified in the status field, for example,

    "message": "Smart contract transaction successfully mined";
    
  • timestamp – the Unix Timestamp (in milliseconds), marking the time of the smart contract call;

  • 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"
 }

Note

ContractExecutionStatuses gRPC method returns the same information as the GET /contracts/status/{id} REST method.

GET /contracts/{contractId}

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

Response example:

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

The GET /contracts/{contractId} and POST /contracts/{contractId} methods return the same response.

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"
  }
]

The POST /contracts/{contractId} and GET /contracts/{contractId} methods return the same response.

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}

The method returns the {key} value of the executed smart contract by its identifier.

Response example:

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

GET /contracts/balance/details/{ContractID}

The method returns the detailed information about the smart contract balance in system tokens by the {ContractID} smart contract identifier. The method response contains the following information about the smart contract balance:

  • regular – the actual smart contract balance. For instance, this may be the number of WEST system tokens transferred to the balance of the smart contract in the payments field of the 103. CreateContract Transaction version 5 or 104. CallContract Transaction version 5;

  • leasedOut – the number of system tokens that the smart contract leased to some address. After the lease is cancelled, the smart contract balance is updated and the funds are returned to the smart contract balance;

  • available – the number of system tokens available for use on the smart contract balance. The value of this field is calculated from the values of the two fields above:

    available = regular - leasedOut

    After the lease is canceled, the value of this parameter is also updated.

For example, if a smart contract was created and had 10 WEST transferred to its balance, and then the smart contract leased 4 WEST to some address, the method returns the following values:

  • Regular = 10

  • LeasedOut = 4

  • Available = 6

After the lease is cancelled, the method will return the following values:

  • Regular = 10

  • LeasedOut = 0

  • Available = 10

Response example:

GET /contracts/balance/details/{ContractID}:
{
  "contractId": "CbGnXsi84QrwZYqJ4jpjVvwyBhXXCiS9axVMci4YNRDq",
  "regular": 40,
  "leasedOut": 20,
  "available": 20
}
See also