Installation and usage of the platform

REST API: transactions

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

Methods of the transactions group are provided to work with transactions:

  • Signing and sending transactions:

  • Retrieving information about transactions:

Signing and sending transactions

The node REST API uses a JSON representation of a transaction to send requests.

The basic principles of work with transactions are given in the Transactions of the blockchain platform. A description of the fields for each transaction is given in the Description of transactions section.

POST /transactions/sign

The POST /transactions/sign method is used to sign transactions. This method signs the transaction with the sender’s private key stored in the keystore of the node. To sign requests with the key from the keystore of the node, be sure to specify the key pair password in the password field.

Example signature request transaction 3:

POST /transactions/sign:
{
 "type": 3,
 "version": 2,
 "name": "Test Asset 1",
 "quantity": 100000000000,
 "description": "Some description",
 "sender": "3FSCKyfFo3566zwiJjSFLBwKvd826KXUaqR",
 "decimals": 8,
 "reissuable": true,
 "password": "1234",
 "fee": 100000000
}

The POST /transactions/sign method in the response returns the fields needed to publish the transaction.

Example response with transaction 3:

POST /transactions/sign:
{
  "type": 3,
  "id": "DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB",
  "sender": "3N65yEf31ojBZUvpu4LCo7n8D73juFtheUJ",
  "senderPublicKey": "C1ADP1tNGuSLTiQrfNRPhgXx59nCrwrZFRV4AHpfKBpZ",
  "fee": 100000000,
  "timestamp": 1549378509516,
  "proofs": [ "NqZGcbcQ82FZrPh6aCEjuo9nNnkPTvyhrNq329YWydaYcZTywXUwDxFAknTMEGuFrEndCjXBtrueLWaqbJhpeiG" ],
  "version": 2,
  "assetId": "DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB",
  "name": "Test Asset 1",
  "quantity": 10000,
  "reissuable": true,
  "decimals": 8,
  "description": "Some description",
  "chainId": 84,
  "script": "base64:AQa3b8tH",
  "height": 60719
}

POST /transactions/broadcast

The POST /transactions/broadcast method is designed to broadcast a transaction. The response fields of the sign method are input to this method. A transaction can also be sent to the blockchain using other tools given in the article Transactions of the blockchain platform.

When a new user, who is not the node owner, makes his first transaction, he must fill in the certificates query field with his certificate chain. In other cases, the certificates field is not required.

An example of a POST /transactions/broadcast method request

POST /transactions/broadcast:
{
   "type": 3,
   "id": "DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB",
   "sender": "3N65yEf31ojBZUvpu4LCo7n8D73juFtheUJ",
   "senderPublicKey": "C1ADP1tNGuSLTiQrfNRPhgXx59nCrwrZFRV4AHpfKBpZ",
   "fee": 100000000,
   "timestamp": 1549378509516,
   "proofs": [ "NqZGcbcQ82FZrPh6aCEjuo9nNnkPTvyhrNq329YWydaYcZTywXUwDxFAknTMEGuFrEndCjXBtrueLWaqbJhpeiG" ],
   "version": 2,
   "assetId": "DnK5Xfi2wXUJx9BjK9X6ZpFdTLdq2GtWH9pWrcxcmrhB",
   "name": "Test Asset 1",
   "quantity": 10000,
   "reissuable": true,
   "decimals": 8,
   "description": "Some description",
   "chainId": 84,
   "script": "base64:AQa3b8tH",
   "height": 60719
   "certificates": ["a", "b", ...]
}

If the transaction is published successfully, the method returns a json with the transaction and the 200OK message.

Note

You can also use the Broadcast and BroadcastWithCerts gRPC methods to send transactions to the blockchain.

POST /transactions/signAndBroadcast

In addition to the separate methods for signing and broadcasting transactions (POST /transactions/sign and POST /transactions/broadcast), there is a combined POST /transactions/signAndBroadcast method.

This method signs the transaction with the sender`s private key and sends the transaction to the blockchain without intermediate information transfer between the methods.

In the request, the signAndBroadcast method accepts the JSON of the transaction to be signed. JSON representations of transactions are given in the Description of transactions section. In the response, the method returns the 200 code if the transaction was successfully signed and sent, or an error code.

Method request example with the 103 CreateContract transaction:

POST ​/transactions​/signAndBroadcast:
{
  "type": 103,
  "version": 4,
  "sender": "3NpN3HyHzGj7Ny1k5F9zMMQ2n54TZg86G9D",
  "password": "signing-key-password",
  "image": "registry.yourdomain.com/test-docker-repo/contract:v1.0.0",
  "contractName": "Your contract name",
  "imageHash": "573387bbf50cfdeda462054b8d85d6c24007f91044501250877392e43ff5ed50",
  "params": [
  {
    "type": "string",
    "key": "test_key",
    "value": "test_value"
  }
  ],
  "fee": 100000000,
  "timestamp": 1651487626477,
  "feeAssetId": null,
  "atomicBadge": null,
  "validationPolicy": {
  "type": "majority"
  },
  "apiVersion": "1.0"
}

Information about transactions

The transactions group also includes the following methods of obtaining information about transactions in the blockchain:

GET /transactions/info/{id}

Obtaining information about a transaction by its {id} identifier. The transaction identifier is specified in the POST /transactions/sign or POST /transactions/signAndBroadcast methods response.

The method returns transaction data similar to the POST /transactions/broadcast and POST /transactions/signAndBroadcast methods responses.

Response example:

GET /transactions/info/{id}:
{
  "type": 4,
  "id": "52GG9U2e6foYRKp5vAzsTQ86aDAABfRJ7synz7ohBp19",
  "sender": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
  "senderPublicKey": "CRxqEuxhdZBEHX42MU4FfyJxuHmbDBTaHMhM3Uki7pLw",
  "recipient": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
  "assetId": "E9yZC4cVhCDfbjFJCc9CqkAtkoFy5KaCe64iaxHM2adG",
  "amount": 100000,
  "fee": 100000,
  "timestamp": 1549365736923,
  "attachment": "string",
  "signature": "GknccUA79dBcwWgKjqB7vYHcnsj7caYETfncJhRkkaetbQon7DxbpMmvK9LYqUkirJp17geBJCRTNkHEoAjtsUm",
  "height": 7782
}

GET /transactions/address/{address}/limit/{limit}

The method returns the data of the last {limit} transactions of the address {address}.

For each transaction, data similar to the POST /transactions/broadcast and POST /transactions/signAndBroadcast methods responses are returned.

Response example with one transaction:

GET /transactions/address/{address}/limit/{limit}:
[
[
  {
    "type": 2,
    "id": "4XE4M9eSoVWVdHwDYXqZsXhEc4q8PH9mDMUBegCSBBVHJyP2Yb1ZoGi59c1Qzq2TowLmymLNkFQjWp95CdddnyBW",
    "fee": 100000,
    "timestamp": 1549365736923,
    "signature": "4XE4M9eSoVWVdHwDYXqZsXhEc4q8PH9mDMUBegCSBBVHJyP2Yb1ZoGi59c1Qzq2TowLmymLNkFQjWp95CdddnyBW",
    "sender": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
    "senderPublicKey": "CRxqEuxhdZBEHX42MU4FfyJxuHmbDBTaHMhM3Uki7pLw",
    "recipient": "3N9iRMou3pgmyPbFZn5QZQvBTQBkL2fR6R1",
    "amount": 1000000000
  }
]
]

GET /transactions/unconfirmed

The method returns the data of all the transactions in the UTX pool of the node.

For each transaction, data similar to the POST /transactions/broadcast and POST /transactions/signAndBroadcast methods responses are returned.

Response example with one transaction:

GET /transactions/unconfirmed:
[
  {
    "type": 4,
    "id": "52GG9U2e6foYRKp5vAzsTQ86aDAABfRJ7synz7ohBp19",
    "sender": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
    "senderPublicKey": "CRxqEuxhdZBEHX42MU4FfyJxuHmbDBTaHMhM3Uki7pLw",
    "recipient": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
    "assetId": "E9yZC4cVhCDfbjFJCc9CqkAtkoFy5KaCe64iaxHM2adG",
    "amount": 100000,
    "fee": 100000,
    "timestamp": 1549365736923,
    "attachment": "string",
    "signature": "GknccUA79dBcwWgKjqB7vYHcnsj7caYETfncJhRkkaetbQon7DxbpMmvK9LYqUkirJp17geBJCRTNkHEoAjtsUm"
  }
]

GET /transactions/unconfirmed/size

The method returns the number of transactions in the UTX pool, that is, the number of transactions that have been sent to the network but have not yet been validated and mined.

Response example:

GET /transactions/unconfirmed/size:
{
  "size": 4
}

Note

Use the UtxInfo gRPC method to retrieve the UTX pool size in bytes and kilobytes.

GET /transactions/unconfirmed/info/{id}

The method returns the data of the transaction that is in the UTX pool by its {id}.

The method response contains transaction data similar to the POST /transactions/broadcast and POST /transactions/signAndBroadcast methods’ responses.

Response example:

GET /transactions/unconfirmed/info/{id}:
{
  "type": 4,
  "id": "52GG9U2e6foYRKp5vAzsTQ86aDAABfRJ7synz7ohBp19",
  "sender": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
  "senderPublicKey": "CRxqEuxhdZBEHX42MU4FfyJxuHmbDBTaHMhM3Uki7pLw",
  "recipient": "3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8",
  "assetId": "E9yZC4cVhCDfbjFJCc9CqkAtkoFy5KaCe64iaxHM2adG",
  "amount": 100000,
  "fee": 100000,
  "timestamp": 1549365736923,
  "attachment": "string",
  "signature": "GknccUA79dBcwWgKjqB7vYHcnsj7caYETfncJhRkkaetbQon7DxbpMmvK9LYqUkirJp17geBJCRTNkHEoAjtsUm",
  "height": 7782
}

POST /transactions/calculateFee

The method returns the amount of commission for the sent transaction.

The request specifies parameters similar to POST /transactions/broadcast request. The method’s response returns the identifier of the asset where the commission is charged (null for WAVES).

Response example:

POST /transactions/calculateFee:
{
  "feeAssetId": null,
  "feeAmount": 10000
}
See also