Installation and usage of the platform
REST API: information about smart contracts¶
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:
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:
GET /contracts/status/{id}¶
The method returns the status of the executed smart contract creation transaction 103 Create Contract, smart contract call transaction Call Contract, or smart contract update transaction Update Contract by the transaction identifier {id}
transaction identifier.
Even if the node restarts after sending the transaction to the blockchain, the method will return the correct state 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 execution status:SUCCESS
– the transaction has successfully entered the block;ERROR
– non-critical error; the call is rejected; for example, a business error, the contract is not executed;FAILURE
– critical error, the call is rejected; for example, a system error during the execution of the smart contract.
code
– numeric code of an error during smart contract execution (if any); in case of a WASM smart contract, the method will return WASM smart contract error code; in case of a Docker smart contract, a user-defined error code or other error may be returned.message
– transaction status message; contains additional information about the status specified in thestatus
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:
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. The result is returned in key-value pairs as an array of objects with the data type specified.
Response example:
The GET /contracts/{contractId} and POST /contracts/{contractId} methods return the same response.
Note
There is a similar method for confidential smart contracts: GET /confidential-contracts/{contractId}.
POST /contracts/{contractId}¶
The method returns the selected 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:
The POST /contracts/{contractId} and GET /contracts/{contractId} methods return the same response.
Note
There is a similar method for confidential smart contracts: GET /confidential-contracts/{contractId}.
GET /contracts/executed-tx-for/{id}¶
The method returns the result of smart contract execution by the identifier of a 105 ExecutedContract Transaction.
The method response returns transaction 105 data, including the smart contract execution results in the resultsMap
field (if version 5 of 105 transaction was used) or in the results
field (if version 4 or earlier was used) and statusCode
.
Response example:
Note
There is a similar method for confidential smart contracts: GET /confidential-contracts/tx/{executable-tx-id}.
GET /contracts/{contractId}/{key}¶
The method returns the {key} value of the executed smart contract by its identifier.
Response example:
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 thepayments
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/{contractId}¶
The method returns summary information about the balance of the smart contract, whose identifier is passed as contractId
, in WEST system tokens:
assetId
– asset identifier; since the method returns the balance in system tokens, the field will always be empty;
balance
– smart contract balance;int
type value;
decimals
– the number of decimal places of the token used; for WEST it has a value of 8.
Response example:
Note
GetContractBalances gRPC method also returns smart contract balance information.
GET /contracts/asset-balance/{contractId}/{assetId}¶
The method returns the balance of the contract, whose identifier is passed as contractId
, in the token, whose identifier is passed as assetId
:
assetId
– asset identifier;
balance
– smart contract balance;int
type value;
decimals
– the number of decimal places of the token used.
Response example:
Note
GetContractBalances gRPC method also returns smart contract balance information.
POST /contracts/asset-balances¶
The method returns the balances of the contract whose identifier is passed as contractId
in all the tokens whose identifiers are passed as a set of strings in the assetIds
field. For each asset, the following information is returned:
assetId
– asset identifier;
balance
– the balance of the smart contract in this asset;int
type value ;
decimals
– the number of decimal places of the token used.
Request and response example:
Note
GetContractBalances gRPC method also returns smart contract balance information.