So if you want to be able to run them as separate runs, you’ll still need some way of communicating between them. One mechanism we provide for that is by serializing DAML values as JSON through the --input-file
and --output-file
options to daml script
. So in your case, you should make sure that the end result of the script in MoorgateCreate
returns the ContractID of the contract it has created, save that as an --output-file
, and then when you run the second script, you can use that same file as the --input-file
.
You can find out how DAML-LF values translate to JSON here, though in this case you may not need to look at it at all as long as you ensure that the types align in your DAML code.
In particular, you’ll want for the second script to be a function (the first one probably shouldn’t be), and for that function to take as argument the same type as the output type of the first script.
Here’s a small, self-contained, concrete example. The Main.daml
file would read:
module Main where
import Daml.Script
template Asset
with
p: Party
mark: Text
where
signatory p
nonconsuming choice Echo: Text
with
msg: Text
controller p
do
return $ mark <> msg
step1: Text -> Script (ContractId Asset)
step1 mark = script do
alice <- allocatePartyWithHint "alice" (PartyIdHint "alice")
submit alice $ createCmd Asset with p = alice, mark
step2: ContractId Asset -> Script ()
step2 cid = script do
-- created by step 1
let Some alice = partyFromText "alice"
msg <- submit alice $ exerciseCmd cid Echo with msg = "hello"
debug msg
The important point here is that the step1
function returns a ContractId Asset
, and the step2
function takes a ContractId Asset
as an argument. So then you can run (assuming a project named t
because that’s my default name for projects, and after having started a sandbox somewhere with daml sandbox
):
daml build
daml ledger upload-dar .daml/dist/t-0.0.1.dar --host localhost --port 6865
echo '"mark1"' > input_step_1.json
daml script --dar .daml/dist/t-0.0.1.dar \
--ledger-host localhost \
--ledger-port 6865 \
--script-name Main:step1 \
--input-file input_step_1.json \
--output-file output_step_1.json
and that should create a file output_step_1.json
with a contract ID in it. That’s not a very readable format, but we can pass it back into the next script:
daml script --dar .daml/dist/t-0.0.1.dar \
--ledger-host localhost \
--ledger-port 6865 \
--script-name Main:step2 \
--input-file output_step_1.json
And you should see something like:
[DA.Internal.Prelude:540]: "mark1hello"
An important point compared to your existing code is that there is no link between step1 and step2 in DAML, except for the return/input types matching. In particular, step2 does not call step1.
Hope that helps.