Skip to content

ORIGYN-SA/candid_stringify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Candid Stringify

Overview

A Motoko library to convert any Candid data to a string.

Install

  • Install Mops
  • Run mops add candid_stringify in your project directory.
  • Run mops add base candid itertools xtended-numbers to install dependencies.
  • Make sure you add mops to your dfx file
...
  "defaults": {
    "build": {
      "packtool": "mops sources"
    }
  },
...

Usage


import C "candid_stringify";

actor {
    
  type ComplexSample = {
    name : Text;
    age : Int;
    owner : Principal;
    address : {
      street : Text;
      phone : ?Text;
      location : {
        state : Text; 
      };
    };
    language : {
      #english : Text;
      #spanish : Text;
      #french : Text;
    };
    music : [MusicTypes];

  };

  type MusicTypes = {
    rock : Bool;
    dance : Text;
  };
    

  public func stringify_record(i : ComplexSample) : async Text {
    var blob = to_candid (i);

    C.stringify(blob, ["name", "age", "owner", "address", "street", "phone", "location", "state", "language", "english","spanish", "french","music", "rock", "dance" ]);
  };
};

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published