How to Choose the Data Type on Honeycomb Marketplace

0 4

In our recent article that gave a general overview of Honeycomb Marketplace, we mentioned that you needed to select the Data Type of the job that you want to use. In this article, we are going to delve into the details of this subject.

Solidity is a statically-typed language, which means that the compiler needs to know the types of all variables at compile-time. This includes the answer returned by the oracle. For example, we can say:

int256 btcPriceChange;
btcPriceChange = getBtcPriceChangeFromOracle();

Note that we declared that btcPriceChange is of type int256 (a signed integer represented with 256 bits), then wrote the value returned by getBtcPriceChangeFromOracle() on it. This implies that the oracle should know that their response is going to get treated as an int256, and format its answer accordingly.

Chainlink currently supports 4 different Solidity data types:

  • int256: A signed integer represented with 256 bits
  • uint256: An unsigned integer represented with 256 bits
  • bool: A boolean value (i.e., true/false)
  • bytes32: A byte-array of size 32 (usually used to store up to 32 ASCII characters)

As the smart contract developer, you need to signal the oracle what data format you are going to treat the response as. At Honeycomb, we solve this problem by creating a job for each data type. When you choose a different data type from the drop-down menu, the respective job listings get displayed.

  • int256: If the response is a number that can be both positive and negative (e.g., temperature), use a signed integer.
  • uint256: If the response is a number that is never going to be negative (e.g., exchange rate), use an unsigned integer.
  • bool: If the response is a boolean value (i.e., true/false), use the boolean type.
  • bytes32: If the response is a string (i.e., a piece of text), use a fixed size byte-array.

Note: Solidity only supports integer numbers out of the box. If you are going to be working with non-integers, you need to have the oracle convert them to integers for you beforehand. We are going to cover this subject in another article. For this article’s purposes, only consider if the number can be negative or not.

I called the /convert path of the Fixer API with the following parameters (meaning that I want to convert 10 US Dollars to Euros):

"from": "USD",
"to": "EUR",
"amount": 10

The API responded with:

"info": {
"rate": 0.904871
"timestamp": 1573927446
"query": {
"from": "USD",
"to": "EUR",
"amount": 10
"result": 9.04871,
"success": true

(I used the Test button on Honeycomb Marketplace to do this. We are going to dedicate an article on that .)

It is most likely that we want the result field, which is 9.04871. This value is found by multiplying the exchange rate (0.904871) with the amount (10). Since both of these numbers are always positive, so will our answer be. Then, we should be using the job listing that returns an uint256. Would it be a problem if we used int256? Not likely, but it’s good practice to use the correct type for the job. What would happen if we used bytes32? We would have gotten our answer as ASCII characters inside a byte-array (so the first element would have been 9, the second would have been ., etc.).

What if we wanted to get the date? That is not a number or a boolean value, so we should use bytes32. How about info.timestamp? That is always going to be an unsigned integer, so feel free to use uint256. The field success has a boolean value inside, so you would use bool. I’m sure you got the idea.

Now you know the 4 data types that Chainlink oracles can return (for now), when to use which, and how to find the corresponding job listing on Honeycomb Marketplace!

You might also like

Pin It on Pinterest

Share This

Share this post with your friends!

WhatsApp chat