2

I would like to write an application that interacts with the DAML ledger but as of the SDK 0.11.3 the only documented bindings are for Java and JavaScript.

Is there a way to use the Ledger API from other languages?

stefanobaghino
  • 11,253
  • 4
  • 35
  • 63

1 Answers1

4

The Ledger API is a set of services exposed through gRPC, which uses Protocol Buffers as its own interface definition language.

The bindings documented as part of the SDK build on top of the code generated from gRPC to offer more features and a more idiomatic API.

You can still use gRPC directly to generate the code necessary to interact with the Ledger API. As of gRPC 1.15.1, supported languages (and/or platforms) include:

  • C++
  • Java
  • Python
  • Go
  • Ruby
  • C#
  • Node.js
  • Android Java
  • Objective-C
  • PHP
  • Dart

The following are the first steps common to all languages to create an example project. If you already have a project and would like to add bindings in a language for which bindings are not available, skip to step 4.

  1. Create a new directory for your project and cd into it

    mkdir daml-project && cd daml-project
    
  2. Create a directory for your DAML models and put a model into it. For now an empty model will do (you can put a model of your choosing at a later time).

    mkdir daml && echo -e "daml 1.2\nmodule Empty where" > daml/Empty.daml
    
  3. Create a project descriptor (da.yaml file) with the following contents:

    project:
      sdk-version: 0.11.3
      name: daml-project
      source: daml/Empty.daml
    version: 2
    
  4. Run the following command to add the Ledger API gRPC service definitions to your project:

    da add ledger-api-protos
    

At this point the directory protobuf should have been added to your project. You can use these files to generate bindings to the Ledger API in one of the languages supported by gRPC.

The procedure on how to generate the code for your target language is described by the gRPC official documentation.

stefanobaghino
  • 11,253
  • 4
  • 35
  • 63
  • 1
    Which visual code extension do you recommend for viewing the proto buffer files? – Meyer Auslander Feb 26 '19 at 20:45
  • 1
    Is there any documentation explaining the directories and files generated by `da add ledger-api-protos`? – Meyer Auslander Feb 26 '19 at 20:46
  • 1
    I noticed the Java bindings provided by Digital Asset are vast. They include different 'layers', 'reactive components', predefined classe for the Ledger client etc. Will an application written in a language like PHP need to create all these bindings from scratch? – Meyer Auslander Feb 26 '19 at 21:41
  • 1. I don't have any recommendation regarding VS Code extensions to read Proto files. – stefanobaghino Feb 27 '19 at 07:24
  • 2. There is no file-by-file explanation, but https://docs.daml.com/packages/ledger-api-introduction/index.html offers an overview of the Ledger API that covers all topics at a higher level while being language-agnostic. It should be fairly easy to identify which file cover which service. – stefanobaghino Feb 27 '19 at 07:24
  • 3. You don't necessarily have to recreate everything. You can use the generated code as is. We added facilities on top of the generated code to make the user's life easier. You'll probably want to add your abstractions to make your own life easier. If that's the case, I'd recommend making bindings that suit you and your specific context. – stefanobaghino Feb 27 '19 at 07:24
  • I noticed DA has an experimental section that has a link to node.js bindings. Now I have an option to write my client at in node.js or php. Will it be more time-efficient to do it in node instead of php since there are bindings in node? I am finding doing it in php to be difficult since there is no documentation on it. – Meyer Auslander Mar 04 '19 at 22:44