Safely storing the values of event fields

Hey I need some suggestion. I want to store Flow’s event data in my own database, I’m having a trouble figuring out how to store the event field’s values since I’m storing for any arbitrary events (not for any known events).

I’m new to Go, since the event field’s data type is cadence.Value and calling ToGoValue() would give me an interface{} which could be anything from simple integers to nested arrays, how could I serialize and store it so that I could safely deserialize it later?

Ok I just found about this:, perfect for my usage, it even works for optionals :slight_smile:

bytes, err := json.Encode(eventField)
serialized = string(bytes[:])

@yondercode Yep, you can use JSON serialization to achieve that. In the future it would be nice to also have a more compact serialization format for the values.

What database are you using?

Alright I’ve been using json.Encode successfully. I’m using postgres as the database and storing event field values in jsonb type.

It allows easy querying for tracking FTs transfers and NFTs ownership history