Hong Kong Daml Meetup!

Hello Daml’ers!

My name is Max, Developer Advocate for the APAC region. Last week we held our first ever Daml meetup in Hong Kong where I gave a presentation on Daml smart contracts and the adoption of blockchain in the enterprise world. We had 25 people attend our event, including @kctam and 8 people streaming in via Zoom. You can watch the recording here if you missed it!

There was a good mix of developers and business people attending this meetup, and many engaging questions were raised.

The following are two questions from the meetup that I wanted to highlight:

“We’re a tech supply chain company, evaluating whether or not blockchain technology is for us. The biggest question we have is, how do we prevent the garbage in, garbage out phenomenon? Say, a supplier might be giving us the wrong data, how can implementing blockchain help with that?”

By adopting a distributed model, the system itself can influence participating parties (factory, shipping, warehouse, retail store) that are in this network to act honestly. By increasing transparency, accountability, and removing data silos where necessary parties, participants will be encouraged ( or pressured) to act honestly - And that’s already an improvement from the existing centralised databases models which introduce data silos and further cloud accountability among collaborators.

In addition, Daml models can also enforce some data quality, for example no one can create data that depends on an earlier contract that doesn’t exist.

These types of data quality guarantees happen by default in Daml rather than needing to be specifically coded.

To be frank, adopting a distributed ledger infrastructure (or blockchain infrastructure) cannot directly solve the issue of input errors (intentional or unintentional) from humans. In a digital world, and in the context of security and data validity, humans are the weakest link in the chain. In fact, it doesn’t matter if you’re on a blockchain, or a centralized database, If a user inputs wrong information, it’ll remain incorrect up until final data consumption. Hence garbage in, garbage out. Daml may be platform agnostic, but so is human error.

Any thoughts on this the above?

And the second question:

“How exactly does Daml work with the frontend…You mentioned you can interact with it using JavaScript?”

After writing your Daml smart contract code, using the code generator from the SDK, a JavaScript / Typescript library is generated so that you can import the generated classes into your .js file and interact directly with the smart contract APIs.

For example, if I’ve created a TokenArt contract using Daml ( a smart contract template representing a piece of art), in your .js file, to access that smart contract, you can first import it as below:

​​import { TokenArt } from "@daml.js/daml-social-network"

To retrieve a contract in the ledger, do the following:

const offer = await ledger.fetchByKey(
   { _1: issuer, _2: owner, _3: image })

What the above does is retrieves all tokenOffer contracts by issuer name, owner name, and an image Id.

And to exercise the choices on a contract, you do the below:

const acceptOffer = async (contractId: ContractId<TokenArt.TokenPurchaseOffer>) => { 
   await ledger.exercise(TokenArt.TokenPurchaseOffer.AcceptPurchaseOffer, contractId, {})

There is no need to write your own APIs to have the frontend interact with the smart contracts. The generated Javascript library allows developers to directly interact with the ledger over the JSON API. Alternatively you can skip the codegen and use the JSON API directly. Similarly we have a codegen for Java that works with our gRPC/protobuf Ledger API as another way of having your application communicate with a Daml application, depending on your needs.

You can read more about the Javascript Client Libraries here.

If you’d like to follow a quick tutorial to try out Daml, try this social media application sample.

I’m hoping to do more meetups, some code-alongs, and more activities to bring the community together in an interactive way. If you guys have any ideas, please do let me know!

Last but not least, this is a great platform to ask any Daml / blockchain/ infra related questions. Our staff and community members are always happy to engage with new users, so expect some pretty quick responses!

Whether you are a developer looking to explore coding smart contracts, a CTO experimenting with moving onto a distributed ledger model, or a business lead trying to understand what the benefits of blockchain and smart contracts can do for your business, please, ask away!