Script throws variable not in scope

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 Likes

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.

2 Likes

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
2 Likes