# Data Objects

One of the primary funcitons of Jigu is to allow developers to work seamlessly with the data on the Terra blockchain. Data Objects are special Python classes that allow you to work with blockchain data using native Python types, handling the marshalling and unmarshalling for you through a series of automatic schema validation and type conversion.

All Data Objects are made directly available as aliases through the jigu.core namespace, i.e. you can do:

# from jigu.core.sdk import Coin
from jigu.core import Coin

# Serialization

All core Data Objects are serializable into a JSON format that can be understood and consumed by nodes on the Terra blockchain. Once instantiated, call .to_json() on the object to encode the object into JSON.

from jigu.core import Coin

c = Coin('uluna', 25_000_000)
c.to_json() # -> json string

# Deserialization

Whenever you are using the module APIs from the Terra instance, Jigu automatically deserializes the resulting response from the node into the proper Data Object most convenient for processing within Python. You can manually perform this deserialization by using the .from_data() method, passing in the dictionary / value reconstructed from JSON.

import json
from jigu.core import Coins

data = """
[{
    "denom": "uusd",
    "amount": "1000000"
},
{
    "denom": "ukrw",
    "amount": "1000000000"
}]
"""

cs = Coins.from_data(json.loads(data))
cs["uusd"] # -> Coin('uusd', 1000000)
Updated on: 2/19/2020, 12:03:33 AM