Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/I would like to ask how to call my python methods in daml?Forum ↗

I would like to ask how to call my python methods in daml?

App Development2 posts166 viewsLast activity Feb 2023
TI
Tinglei_ZhangOP
Feb 2023

I would like to ask how to call my python methods in daml? I wanted to implement keccak_256 encryption, but only found sha256 in daml.

CO
cocreature
Feb 2023

You cannot call into python code (or any other language) from within Daml.

If you need to communicate with outside services, you can create a request contract in your Daml code and then compute the response on the client side. Something like this:

template Keccak_256Request
  with
    p : Party
    textToHash : Text
  where
    signatory p

    choice Respond : ()
      with
        hash : Text
      controller p
      do -- fill in how you want to continue here
         pure ()

test = script do
  p <- allocateParty "p"
  -- Create the request in your Daml code
  cid <- submit p $ createCmd (Keccak_256Request p "text to hash")
  -- compute the hash in your python code
  -- submit the exercise from your python code with the right hash
  submit p $ exerciseCmd cid (Respond "fill in the hash here")
← Back to Discussions