Skip to main content
Build one savings vault on mainnet, then spend it. Paste the TypeScript blocks into vault.ts in order. The savings vault is a fixed-party vault with one owner.
If you build with an AI agent, install the contract skills. They guide the agent through writing, compiling, spending, and testing a contract.

Setup

You need Rust 1.85 or newer and Node.js 22.13 or later. Set type to module in package.json. The compiler page describes the language.
service selects the operator’s endpoints and the Esplora server for its network. storage holds the contracts that you register, here in memory (Watch and persist). Node.js has no EventSource by default, so call configureEventSource before Arkade.connect, or the client does not report contract events.
vault.ts
For another deployment, replace the Arkade.connect call with one that gives the operator URL and the emulator URL. Without an emulator URL, covenant paths stay off.

Create a Vault

release pays one output to recipientScript after the emulator clock passes unlockAt. unilateral is the exit path: if the operator is unavailable, the owner’s signature alone spends the output after you unroll it and the operator’s exit delay passes. The client binds serverExitDelay, so do not pass an argument for it.
savings_vault.ark
Load the artifact that you compiled. The SDK function programFromArtifact reads the output of arkadec. The function parseArtifact reads a different format. The address depends on the exit delay that the operator reports when you create the contract. The client binds serverExitDelay from that value (CSV delays). If the delay changes, a new contract from the same artifact and arguments has another address. Register the contract, because the stored row keeps the delay (Watch and persist). A ScriptPubKey parameter binds as two arguments. Pass the 32-byte witness program as recipientScript.program and the witness version as recipientScript.version. For an Arkade address, the program is vtxoTaprootKey and the version is 1n. The covenant compares both, so the payout output must use that program and version.
An argument is a Uint8Array, a bigint, or a number. A bool is 0 or 1. A child contract that you create with new in the source binds as contract_<Name>_<args>. The value is the 32-byte witness program of the child.

Watch and persist

contract.register() and contract.on() need a contract manager. Pass storage: { contractRepository } or contractManager: await wallet.getContractManager() to Arkade.connect, never both (Setup). The in-memory repository loses its rows on exit. To persist contracts, use a repository from Storage. contract.on() registers the contract and reports vtxo_received, vtxo_spent, and connection_reset. It does not replay past outputs or events missed during a reconnect. Call contract.getVtxos() after you subscribe and on every connection_reset. It returns spent outputs too. fromContract rebuilds a contract from its stored row. The address survives a signer rotation or an exit delay change.

Spend

The spend takes one contract output. .from(output) places that output at input 0. Other inputs are sibling outputs when the function needs them, for example an oracle output or a standing offer. The savings vault and the escrow assert a single input. The output script is the full pkScript, not the witness program that you gave to the constructor. Send funds to the printed address first. This spends real sats.
client.dispose() stops the contract manager that Arkade.connect built from storage. Call it when the script is done, so the process can exit. It doesn’t stop a manager that you passed as contractManager: that manager belongs to the wallet, so call await wallet.dispose() instead. The identity signs input 0 only when its key is in the path of the function. The identity also signs each funded input. A covenant send goes to the emulator (submitTx). The emulator runs the covenant’s script and cosigns only when the script passes. The emulator then submits the transaction to the operator and finalizes it. A tapscript send goes to the operator (submitTx, then finalizeTx). A signature argument is a BIP340 Schnorr signature of the message. Two covenant inputs need one emulator entry each. A contract output expires with its batch, as other outputs do (virtual output management).

CSV delays

An exit path passes serverExitDelay to older. Do not pass an argument for it, because the client binds the exit delay that the operator reports. To renew an output in a batch swap, its contract needs an older path. Keep the artifact and the constructor arguments, and register the contract. Its stored row keeps the program, the arguments, the exit delay, and the operator key, so fromContract rebuilds the same address if the operator changes them. To use a longer delay, declare an integer parameter and pass it to older. A parameter binds as a raw BIP68 sequence. The operator rejects a block sequence on an exit path, except on regtest. Use seconds. The value must be a multiple of 512 and at least the exit delay of the operator. The operator reports unilateralExitDelay in seconds when the value is 512 or more. Otherwise, it reports blocks.