# Set a price for an asset

TIP

In order to perform this transaction you need to be an oracle.
If you wish to become one, please take a look at the "Adding an oracle" page

If you have been added as an oracle you can set a price into the blockchain once every block.
This means that trying to set a price for the same asset more than once every 6 seconds (the estimated block time) will result in an error when trying to send the transactions.

# Transaction message

In order to set a raw price for a specific asset, you need to create and sign the following message.

{
  "type": "commercio/MsgSetPrice",
  "value": {
    "oracle": "<Did of the oracle>",
    "price": {
      "asset_name": "<Name of the asset>",
      "value": "<Price of the asset (supports decimal numbers)>",
      "expiry": "<Block height after which the price should be considered invalid>"
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11

# Fields requirements

Field Required
oracle Yes
price Yes

# price

Field Required
asset_name Yes
value Yes *1
expiry Yes
  • *1 The value field value must have a 18 decimal digits.
    For example, to set price 1 you must use 1.000000000000000000.

# About the expiration

When sending the above message, you will need to specify a valid expiry value.
The best way to do so is to:

  1. Query the latest block height.
    You can do so by using the following REST API:

    /blocks/latest
    
    1
  2. Once you have the latest block height, add to it k=n6k = \frac{n}{6} where nn is the number of seconds you want the price to be valid for.

Please note that adding a price with a block height equals or lower than the current block height will result in the price never be considered valid and thus never be taken into consideration.

We suggest you to choose a value of k=10k = 10 which will make the price valid for more or less 1 minute.

# Action type

If you want to list past transactions including this kind of message, you need to use the following message.action value:

setPrice
1