Using the DAML Ledger API from a language other than Java or JavaScript

血红的双手。 提交于 2019-12-11 04:34:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/54881601/using-the-daml-ledger-api-from-a-language-other-than-java-or-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!