Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] - document how to JSON-ify a "typed" datum. #4398

Open
Tracked by #4144
CarlosLopezDeLara opened this issue Aug 26, 2022 · 3 comments
Open
Tracked by #4144

[Docs] - document how to JSON-ify a "typed" datum. #4398

CarlosLopezDeLara opened this issue Aug 26, 2022 · 3 comments
Labels
comp: cardano-api documentation enhancement New feature or request type: documentation Improvements or additions to documentation type: enhancement An improvement on the existing functionality user type: internal Created by an IOG employee

Comments

@CarlosLopezDeLara
Copy link
Contributor

Document how to convert a "typed" datum to cardano-api's ScriptData ?

Better-->
Can we have a function that can convert any typed datum to a ScriptData.

@CarlosLopezDeLara CarlosLopezDeLara moved this from 🆕 New to 📋 Backlog (needs grooming) in Node CLI/API 2022 Oct 20, 2022
@dorin100 dorin100 added type: enhancement An improvement on the existing functionality type: documentation Improvements or additions to documentation user type: internal Created by an IOG employee comp: cardano-api labels Oct 24, 2022
@mesudip
Copy link

mesudip commented Dec 2, 2022

Converting script data to json is straightforward with cardano-api's scriptDataToJson function

dataumStringJson :: ScriptData -> String
dataumStringJson  _data = BS8.unpack $ encode $ scriptDataToJson ScriptDataJsonDetailedSchema   _data

To convert plutus data to cardano api ScriptData, cardano-api already exposes fromPlutusData function.

  • And Plutus.Tx.mkIsDataIndexed makes the class instance of ToData. Thus , you can use the function below to convert pluuus data to cardano-api's ScriptData.
dataToScriptData :: (ToData a1) => a1 -> ScriptData
dataToScriptData sData =  fromPlutusData $ toData sData

@CarlosLopezDeLara , where do you suggest the doc to be added?

@koslambrou
Copy link
Contributor

@CarlosLopezDeLara Since there's no docs for cardano-api, should we put those documentation examples as Haddock documentation directly in the module Cardano.Api.ScriptData?

@CarlosLopezDeLara
Copy link
Contributor Author

CarlosLopezDeLara commented Dec 12, 2022

should we put those documentation examples as Haddock documentation directly in the module Cardano.Api.ScriptData?

@mesudip @koslambrou I think directly in the module is the best thing to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: cardano-api documentation enhancement New feature or request type: documentation Improvements or additions to documentation type: enhancement An improvement on the existing functionality user type: internal Created by an IOG employee
Projects
None yet
Development

No branches or pull requests

4 participants