Skip to content
CCPEDIAby Unity Nodes
App Development

Script Trigger Point

3 posts148 views1 likesLast activity Dec 2022

  1. kanika_kapoorOP

    template CashBalance
    with
    accountant : Party
    currency : Text
    amount : Decimal
    owner : Party
    account_number : Text
    bank : Party
    bank_address : Text
    bank_telephone : Text
    where
    signatory accountant

    cash_balance_test = script do
    accountant ← allocateParty “Bob”
    alice ← allocateParty “Alice”
    bob ← allocateParty “Bank of Bob”

    submit accountant do
    createCmd CashBalance with
    accountant
    currency = “USD”
    amount = 100.0
    owner = alice
    account_number = “ABC123”
    bank = bob
    bank_address = “High Street”
    bank_telephone = “012 3456 789”

    For above code, I want to understand

    1. what will trigger the cash_balance_test script execution.
      Is that below, if not plz guide.
      daml script --dar .daml/dist/create-daml-app-0.1.0.dar --script-name Refer:cash_balance_test --ledger-host localhost --ledger-port 6865
    2. How can print the result of the code lines so as to understand what value variable holds .
  2. Gary_Verhaegen 1

    That line will indeed run that script. If you want to get a value out of a Daml Script, the best tool we have at the moment is the --output-file flag, which writes the result of the script as JSON.

    To control the result of the script and makesure it has all the information you want, you can put an explicit type marker on your script:

    cash_balance_test : Script Result
    cash_balance_test = script do
      ...
    

    and that will only compile if your script does indeed return a value of type Result, which is what would then be written to the file specificed in the --output-file flag.

  3. a_putkov

    @kanika_kapoor
    Since you’re new to Daml and you haven’t mentioned that you know how to view the results of a Daml Script execution in IDE, it may be worth mentioning in addition to the answer provided by @Gary_Verhaegen that Visual Studio Code IDE automatically executes any Daml Scripts you write against the test ledger. You can view the results of the script execution by clicking on “Script Results” link that appears above the Script declaration (the call to the script function). See Test Templates using Daml Script — Daml SDK 2.4.0 documentation for more details.

    The output of the calls to debug function can also be viewed in Visual Studio Code IDE. They appear at the bottom of the page when you click “Show Transaction View” on the page showing Script Results.