Rúnar Compiler

raw JSON →
0.4.6 verified Fri May 01 auth: no javascript

Rúnar reference compiler (TypeScript to Bitcoin Script) via a 6-pass nanopass pipeline. Version 0.4.6, actively developed. Key differentiators: supports multiple front-end languages (TypeScript, Solidity-like, Move-style, Python) via file extension dispatch; never throws, all errors returned as diagnostics; exports ANF IR and full artifact. Currently in beta.

error SyntaxError: Unexpected token 'export'
cause Source code is parsed as JavaScript without .runar.ts extension; export keyword not supported in older Node.js
fix
Rename file to end with .runar.ts, or pass fileName option with correct extension.
error ERR_REQUIRE_ESM
cause Attempting to require() the ESM-only package from a CommonJS module
fix
Use import syntax (ESM) or dynamic import: const compile = (await import('runar-compiler')).compile;
error TypeError: CompileResult is not a constructor
cause Importing CompileResult as a value instead of a type
fix
Use import type { CompileResult } from 'runar-compiler'; it is an interface, not a class.
breaking Package is ESM-only; no CommonJS support. require() on the package will throw ERR_REQUIRE_ESM.
fix Use import syntax or dynamic import().
gotcha The fileName option must include the correct extension to select the parser (e.g., .runar.ts, .runar.sol). Wrong extension leads to parse errors.
fix Ensure fileName matches the source language extension, e.g., 'contract.runar.ts' for TypeScript, 'contract.runar.sol' for Solidity-like.
gotcha compile() never throws; all errors are returned as diagnostics in the CompileResult. Silently assuming success === true is dangerous.
fix Always check result.success and inspect result.diagnostics for errors.
npm install runar-compiler
yarn add runar-compiler
pnpm add runar-compiler

Compiles a P2PKH smart contract from TypeScript-like source to Bitcoin Script using the runar-compiler.

import { compile } from 'runar-compiler';

const source = `
import { SmartContract, assert, PubKey, Sig, hash160, checkSig } from 'runar-lang';

export class P2PKH extends SmartContract {
  readonly pubKeyHash: ByteString;

  constructor(pubKeyHash: ByteString) {
    super(pubKeyHash);
    this.pubKeyHash = pubKeyHash;
  }

  public unlock(sig: Sig, pubKey: PubKey) {
    assert(hash160(pubKey) === this.pubKeyHash);
    assert(checkSig(sig, pubKey));
  }
}
`;

const result = compile(source, { fileName: 'P2PKH.runar.ts' });

console.log(result.success);
console.log(result.scriptHex);
console.log(result.scriptAsm);