Json
Why?
Venin has native support to store and retrieve basic JavaScript objects (JSONs) using Hedera's File Service. This is particularly handy if you plan on storing some basic data/configuration for your dApp.
Storing a Json
You use a ApiSession for that, like so:
To make things easier, you can also upload any JS object and which will have the same end effect.
So you could replace session.upload(new Json({ theAnswer: 42 })) with a more skimmed-down version: session.upload({ theAnswer: 42 }) making up for a more succinct code.
If you need to pass in/tweak file-transaction options when storing the Json object, you can use the uploads meta-arguments. For instance, if you want to add a memo, just pass it a { _file: { memo: "my json" } } when uploading, like so:
const { session } = await ApiSession.default();
const liveJson = await session.upload(
{ theAnswer: 42 },
{ _file: { memo: "my json" } }
);
//...
The _file property is needed when uploading a file to distinguish it from uploading contract meta-arguments which also allow for fine-tweaking the ContractCreateTransaction call parameters through their own _contract property object.
Besides setting a memo you can pick and use any other fields that the FileCreateTransaction supports.
Retrieving a Json
You'll need its liveJson.id for that which will need to be passed to ApiSession's getLiveJson method:
Deleting a Json
You can delete a LiveJson via the LiveEntity.deleteEntity call. Just do a LiveJson.deleteEntity() to delete the underlying file from the network.
Once deleted, certain operations such as getLiveEntityInfo and, in general, all network-related actions, are no longer available.
The list of restricted operations are inherited from LiveFile which this LiveEntity extends.
Updating a Json
Updating such an entry is possible via the LiveJson.updateEntity(FileFeatures) call with FileFeatures being an object type used by regular LiveFiles.