Rúnar

CLI Reference

The Runar CLI is the primary interface for creating projects, compiling contracts, running tests, and deploying to the BSV network. This page documents every available command and flag. The CLI is distributed as the runar-cli npm package and invoked with the runar command.

Global Options

runar [command] [options]
FlagDescription
--version, -vPrint the Runar CLI version
--help, -hShow help for the command

runar init

Scaffold a new Runar project.

runar init [name]

Arguments

ArgumentDescription
nameName of the project directory to create (optional, default: my-runar-project)

Example

runar init my-project

Generated Structure

my-project/
  src/
    contracts/           # Contract source files
      P2PKH.runar.ts
  tests/               # Test files
    P2PKH.test.ts
  artifacts/           # Compiled output (gitignored)
  package.json
  tsconfig.json
  .gitignore

runar compile

Compile one or more Runar contracts to Bitcoin Script artifacts.

runar compile <source...> [options]

Arguments

ArgumentDescription
sourceOne or more contract source files or a glob pattern

Options

FlagDefaultDescription
--output <dir>./artifactsOutput directory for compiled artifacts
--irfalseInclude ANF intermediate representation in the artifact
--asmfalseInclude human-readable ASM in the artifact
--disable-constant-foldingfalseDisable the constant folding optimization pass

Examples

# Compile a single contract
runar compile contracts/P2PKH.runar.ts

# Compile all contracts in a directory
runar compile contracts/*.runar.ts --output ./artifacts

# Compile with IR and ASM output
runar compile contracts/PriceBet.runar.ts --asm --ir

Output

For each source file, the compiler produces a JSON artifact:

artifacts/
  P2PKH.json
  PriceBet.json

The artifact format is documented in Output Artifacts.

Exit Codes

CodeMeaning
0Compilation succeeded
1Compilation failed (errors in source)
2Configuration or file system error

runar test

Run the test suite. Delegates to vitest under the hood.

runar test [pattern]

Arguments

ArgumentDescription
patternOptional pattern to filter which tests to run

Examples

# Run all tests
runar test

# Run tests matching a pattern
runar test PriceBet

The test runner uses vitest. Additional vitest flags can be passed through your vitest.config.ts or package.json scripts. See The Test Runner for details on the testing framework.

runar debug

Launch an interactive step-through script debugger for a compiled contract artifact.

runar debug <artifact> [options]

Arguments

ArgumentDescription
artifactPath to a compiled JSON artifact (must include sourceMap)

Options

FlagDefaultDescription
-m, --method <name>Public method to invoke
-a, --args <json>Method arguments as a JSON object
-u, --unlock <hex>Raw unlocking script hex (alternative to --method/--args)
-b, --break <loc>Initial breakpoint: opcode index or file:line

Example

runar debug ./artifacts/PriceBet.json --method settle --args '{"price": 60000}'

See Debugging Compiled Script for full usage details.

runar deploy

Deploy a compiled contract to the BSV network.

runar deploy <artifact> [options]

Arguments

ArgumentDescription
artifactPath to the compiled JSON artifact

Options

FlagDefaultDescription
--network <net>requiredTarget network: mainnet or testnet
--key <wif>requiredWIF-encoded private key for funding
--satoshis <n>10000Satoshis to lock in the contract output

Examples

# Deploy to testnet
runar deploy ./artifacts/P2PKH.json \
  --network testnet \
  --key cN1r3... \
  --satoshis 10000

Output

Contract deployed successfully.
  Network:  testnet
  TxID:     a1b2c3d4e5f6...
  Output:   0
  Satoshis: 10000
  Script:   76a914...88ac

Security Notes

  • Avoid passing mainnet private keys as CLI arguments in shared environments (the key appears in shell history).

runar verify

Verify that an on-chain contract matches a compiled artifact.

runar verify <txid> [options]

Arguments

ArgumentDescription
txidTransaction ID of the deployed contract

Options

FlagDefaultDescription
--artifact <path>requiredPath to the compiled artifact to compare against
--network <net>requiredNetwork to query: mainnet or testnet

Examples

# Verify a deployment
runar verify a1b2c3d4e5f6... \
  --artifact ./artifacts/P2PKH.json \
  --network testnet

Output

Verification passed.
  Contract:     P2PKH
  TxID:         a1b2c3d4e5f6...
  Output:       0
  Script match: yes
  Confirmations: 3

runar codegen

Generate typed bindings from a compiled artifact.

runar codegen <artifact...> [options]

Arguments

ArgumentDescription
artifactOne or more compiled JSON artifacts

Options

FlagDefaultDescription
--output <dir>, -o./typesOutput directory for generated files
-l, --lang <lang>tsTarget language: ts, go, rust, python

Examples

# Generate TypeScript types
runar codegen ./artifacts/P2PKH.json --output ./types

# Generate types for all artifacts
runar codegen ./artifacts/*.json

# Generate Go bindings
runar codegen ./artifacts/Token.json --lang go --output ./bindings

Generated Output

For a P2PKH contract, runar codegen produces:

// types/P2PKH.ts
import { RunarContract, Sig, PubKey, Ripemd160 } from 'runar-sdk';

export interface P2PKHConstructorArgs {
  pubKeyHash: Ripemd160;
}

export interface P2PKHMethods {
  unlock(args: { sig: Sig; pubKey: PubKey }): Promise<CallResult>;
}

export type P2PKHContract = RunarContract & P2PKHMethods;

This gives you full IDE autocompletion and type checking when interacting with contracts through the SDK.