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
- Select an action permitted by the template. Create an invitation with
createInvitationor accept one another participant has shared withacceptInvitation. - Use
listMissingRequirementsand provide missing variables, inputs and outputs withappendInvitation. When a script needs other participants’ values, share the invitation and apply the returned update withupdateInvitation. - Calculate the fee and add appropriate change. Review the assembled transaction and use
listOwnInputIndexesto determine which inputs this account can sign. - Sign the required inputs with
signInvitation. CallexecuteActionwith the intendedbroadcastTransactionsetting 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
A Bitcoin Cash record that defines new outputs and, for a payment, identifies the UTXOs being spent.The basic unit of spendable value on Bitcoin Cash, holding satoshis and any attached tokens under the spending rules defined by its locking bytecode.A transaction record that identifies a UTXO to spend and supplies its unlocking bytecode and sequence number.A value made with a private key that lets someone with the corresponding public key verify authorization of the signed data.Software or a device that manages addresses and tracks UTXOs, with signing wallets also holding private keys to authorize payments.The public Bitcoin Cash blockchain on which payments use BCH.The starting secret from which an HD wallet derives its key tree, which BIP39 can derive from a mnemonic and passphrase.An application that uses a decentralized system such as BCH and can ask a wallet to authorize an action or payment.The program in an output that specifies the conditions required to spend it.A shareable identifier a wallet decodes into a payment’s locking script, usually in CashAddr format on BCH.A public Bitcoin Cash test chain that uses test coins and bchtest: addresses to exercise upgrades and applications.A fixed-length digest used to identify data or commit to its contents, such as a transaction ID or public-key hash.The currency unit of Bitcoin Cash, equal to 100,000,000 satoshis.