# Running a pure script without a ledger?

**URL:** <https://forum.canton.network/t/running-a-pure-script-without-a-ledger/4115>\
**Category:** App Development\
**Tags:** daml-sdk\
**Created:** [March 15, 2022, 4:53pm UTC](https://forum.canton.network/t/running-a-pure-script-without-a-ledger/4115 "2022-03-15T16:53:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [March 15, 2022, 4:53pm UTC](https://forum.canton.network/t/running-a-pure-script-without-a-ledger/4115/1 "2022-03-15T16:53:47Z")

</div>

Related to posts

> [@Accessing test data within Scripts](https://discuss.daml.com/t/accessing-test-data-within-scripts/2060):
>
> 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. …

> [@Running DAML scripts - puzzling options](https://discuss.daml.com/t/running-daml-scripts-puzzling-options/3851/3):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Remy](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/remy/32/595_2.png) [@Remy](https://forum.canton.network/u/Remy)\
**Post date:** [March 16, 2022, 9:56am UTC](https://forum.canton.network/t/running-a-pure-script-without-a-ledger/4115/2 "2022-03-16T09:56:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [March 16, 2022, 10:22am UTC](https://forum.canton.network/t/running-a-pure-script-without-a-ledger/4115/3 "2022-03-16T10:22:50Z")

</div>

> [@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.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [March 16, 2022, 10:41am UTC](https://forum.canton.network/t/running-a-pure-script-without-a-ledger/4115/4 "2022-03-16T10:41:49Z")

</div>

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.
