Skip to content
Discussions/App Development/Running a pure script without a ledger?Forum ↗

Running a pure script without a ledger?

App Development4 posts277 viewsLast activity Mar 2022
LU
LucianoOP
Mar 2022

Related to posts

Hi looking at (1) it seems to be common knowledge how to access test data from a Script. But I am failing to figure out how to do that from reading the documentation and this forum. According to the DAML Script docu (2), the --input-file option serves that purpose. But unless I have been overlooking this repeatedly, it is not clear how the script can access that information. And looking at the docu for the Daml.Script library (3) there seems to be no function that can access that information. …
Thanks Moritz for your prompt response. It’s fairly confusing. So running a “daml test” runs all scripts in the project or given DAR file and runs them in a special in-memory emulator? “daml test-script” takes a DAR file, a script identifier and a ledger connection and runs a script against the ledger? “daml script” runs the script on a special in-memory ledger emulator? When wishing to simply open a DAML file with a script in the IDE it means that you start a sandbox and run all scripts in…

Is there a way to run a pure script that doesn’t execute any Commands without connecting to a ledger?
For instance, using daml script but without the --ledger-host option?

What I’m trying to achieve here is to run a scenario : Script Text and output the resulting string.
I could of course fail the script and use debug, but that’s kind of horrible.

RE
Remy
Mar 2022

You two concerns are a bit unrelated.

Currently the Daml script command line requires a ledger to connect to. The only way to run a script without a functional ledger is inside Daml Studio.

On the other hand, to get the output of a script, you can use the option --output-file to specify a file where the result of the script will be written to in JSON format.

LU
Luciano
Mar 2022
Remy:

On the other hand, to get the output of a script, you can use the option --output-file to specify a file where the result of the script will be written to in JSON format.

Yes, I got this bit - I think it’s mentioned in one of the linked posts.

What I don’t want is to have to do is daml start to spin up a ledger every time i run daml script, because I’m not actually reading/writing any contracts. I’m just evaluating a pure function.

Remy:

Currently the Daml script command line requires a ledger to connect to. The only way to run a script without a functional ledger is inside Daml Studio.

Yes, it would have been nice to have this functionality in daml script, so that if I omit --ledger-host, it just uses the secnario-service.

CO
cocreature
Mar 2022

For now, there is no option for this in daml script but you can use daml repl to evaluate your script which does not require a ledger. Note that it doesn’t use the scenario service either, it will just fail for ledger operations but if I understand you correctly that’s fine for your usecase.

← Back to Discussions