Using the DAML Ledger API from a language other th

2019-07-14 07:13发布

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?

标签: daml
1条回答
戒情不戒烟
2楼-- · 2019-07-14 07:43

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.

查看更多
登录 后发表回答