Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 1.19 KB

README.md

File metadata and controls

63 lines (49 loc) · 1.19 KB

🚀 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" ]);
  };
};