Skip to content
Developer Handbook

Dapp connection protocols

XO Stack

On this page

Suppose two people are building one transaction. One supplies a funding UTXO and the other specifies where the tokens should go. XO Stack uses a template to define the action and an invitation to record who has supplied the inputs, outputs, and signatures needed to finish it.

Set up the engine and account

Follow the current @xo-cash package versions in the upstream Getting Started guide. The engine account controls the keys for its selected network and uses wallet policies to derive receiving and change scripts. For mainnet, configure the account and its providers for the mainnet chain. Never ask a user to paste an existing wallet’s seed into an unrelated dapp.

Try the setup on Chipnet

Create a test account in a trusted engine environment and import its first template.

import { Engine, XO_SUPPORTED_NETWORKS } from '@xo-cash/engine';
import { p2pkhTemplate } from '@xo-cash/templates';

const engine = await Engine.create(testMnemonic, {
  network: XO_SUPPORTED_NETWORKS.chipnet,
});
const { templateIdentifier } = await engine.importTemplate(p2pkhTemplate);

await engine.setDefaultPolicies({
  receive: { templateIdentifier },
  change: { templateIdentifier },
  address: { templateIdentifier },
});

Generate receive locking bytecode from the default policy, encode it as a bchtest: address and fund it on Chipnet. Use listSpendableUnspentOutputs() to inspect available inputs.

Complete an invitation

  1. Select an action permitted by the template. Create an invitation with createInvitation or accept one another participant has shared with acceptInvitation.
  2. Use listMissingRequirements and provide missing variables, inputs and outputs with appendInvitation. When a script needs other participants’ values, share the invitation and apply the returned update with updateInvitation.
  3. Calculate the fee and add appropriate change. Review the assembled transaction and use listOwnInputIndexes to determine which inputs this account can sign.
  4. Sign the required inputs with signInvitation. Call executeAction with the intended broadcastTransaction setting and track the returned transaction hash.

Synchronize and close

Use XO’s state facilities to store invitations and update the latest shared version. The sync client exposes SSE and WebSocket transports for shared resources. Application state and participant synchronization are distinct from transaction propagation over BCH. Stop the engine when the account session ends.

XO Stack API reference · XO Stack Getting Started · Engine API