Host party on multiple nodes using participants.json

Hi Turan!
Almost your exact setup is in the create-daml-app example of canton (under examples/04-create-daml-app/canton.init). Here it is:

import better.files._

val createDamlAppDir = File(sys.props.get("create-daml-app-dir").getOrElse("create-daml-app"))

val createDamlAppDar = createDamlAppDir / ".daml" / "dist" / "create-daml-app-0.1.0.dar"

// check that files exist where we expect them
createDamlAppDir.exists || sys.error(s"please setup the create-daml-app example in the current working directly under ${createDamlAppDir}")

createDamlAppDar.exists || sys.error(s"please run daml build in the create-daml-app folder to build the dar file ${createDamlAppDar}")

participant1.domains.connect_local(mydomain)
participant2.domains.connect_local(mydomain)
val alice = participant1.parties.enable("Alice")
val bob = participant2.parties.enable("Bob")
val public = participant1.parties.enable("Public")
participant1.topology.party_to_participant_mappings.authorize(
  TopologyChangeOp.Add,
  party = public,
  participant = participant2.id,
  side = RequestSide.From,
  permission = ParticipantPermission.Observation,
)
participant2.topology.party_to_participant_mappings.authorize(
  TopologyChangeOp.Add,
  party = public,
  participant = participant2.id,
  side = RequestSide.To,
  permission = ParticipantPermission.Observation,
)

participant1.ledger_api.users.create(
  id = "alice",
  actAs = Set(alice.toLf),
  primaryParty = Some(alice.toLf),
  readAs = Set(public.toLf),
)
participant2.ledger_api.users.create(
  id = "bob",
  actAs = Set(bob.toLf),
  primaryParty = Some(bob.toLf),
  readAs = Set(public.toLf),
)

// upload dar file to participants
participants.all.dars.upload(createDamlAppDar.pathAsString)

The relevant part on how to host a party on two participants is described here:
https://docs.daml.com/canton/usermanual/identity_management.html#party-on-two-nodes

Note that the participant.json file is used to route Daml script commands to the right participant. For the Public party you only want to send the command to one participant, not to both.

Finally, createUserOn will create a user on the ledger API of a given participant that can read/act as a given set of parties, while allocatePartyWithHintOn will create a party on a participant. After running the above canton.init script, you wouldn’t have to do any of it, because users and parties have already been allocated.

I hope this helps.

1 Like