Skip to content
CCPEDIAby Unity Nodes
App Development

Script throws variable not in scope

3 posts507 views6 likesLast activity Dec 2020

  1. suchindraOP 2

    I am learning DAML. While following the tutorial at the following location, I am shown an error saying :

    /home/suchivaish/src/Office/DAML/Token.daml:22:16: error: 
    Variable not in scope: script : Scenario (ContractId Token) -> ttypecheck
    

    Tutorial link: https://docs.daml.com/daml/intro/2_DamlScript.html

    My Token.daml file:

    module Token where
    
    template Token
        with
            owner : Party
      
        where
            signatory owner
    
    -- The below code works:
    -- token_test_1 = do
    --     alice <- getParty "Alice"
    --     submit alice do
    --         create Token with owner = alice
    
    token_test_2 = script do
        bob <- getParty "Bob"
        submit bob do
            create Token with owner = bob
    

    Request you to please help me with what is wrong with the above code

  2. Gary_Verhaegen 2

    Hi @suchindra,

    The script function is not part of the core DAML language; it is part of a separate module in the standard library. To get access to it, you have to explicitly important that module. The easiest way to do that is to add this line:

    import Daml.Script 
    

    right after the module ... where line, near the top of the file.

  3. suchindra 2

    Thanks @Gary_Verhaegen :slight_smile:

    Including the import statement enabled the script module to be downloaded. The only additional thing I had to do was

    • Create a daml.yaml file with the following:
    sdk-version: 1.6.1
    name: szabo_car_contract
    version: 1.0.0
    source: daml/Token.daml
    scenario: Token
    parties:
    - Alice
    - Bob
    exposed-modules:
    - Main
    dependencies:
    - daml-prim
    - daml-stdlib
    - daml-script
    
    • And restart the visual studio