@helios-lang/contract-utils
v0.3.25
Published
Convenience and type-safety utilities for using Helios validators from within Typescript
Downloads
505
Readme
contract-utils
Convenience and type-safety utilities for using Helios validators from within Typescript
Helios CLI
Requires Node.js 22 or newer. Install globally with npm:
npm install -g @helios-lang/contract-utils
helios --help
helios compile --format typescript --out-dir ./generated
helios loginhelios compile and hl2ts share the same compiler and options. Compilation searches the current directory for .hl files and does not require login. helios compile --help lists compiler options. The compiler peer dependency is restricted to the supported 0.16/0.17 series.
helios login opens https://helios-lang.io/console with an expiring login request. Connect your wallet, create a project if you have no active projects, compare the code with your terminal, and click Authorize CLI. All active project API keys for that wallet are installed locally. The browser displays You can now close this tab only after the CLI confirms that the file was saved. Use helios login --no-browser to open the printed URL manually, including from another computer. Login expires after ten minutes; cancellation or failure leaves the existing file intact unless it was already saved and only the acknowledgment failed (reported explicitly).
Credentials are stored in a versioned debugger.json file:
| OS | Directory |
| --- | --- |
| Linux | $XDG_CONFIG_HOME/helios, or ~/.config/helios |
| macOS | ~/Library/Application Support/Helios |
| Windows | %APPDATA%\Helios |
Set HELIOS_CONFIG_HOME to override the directory. Unix directories/files use modes 700/600. Windows uses a current-user-only ACL. The JSON has {version:1,selected,profiles}, where selected is a project ID and profiles maps project IDs to {id,name,created_at,apiKey,wallet,endpoint}. Names need not be unique. Re-running login refreshes that wallet's snapshot and removes revoked projects while preserving other wallets. It keeps the selected project when available and otherwise selects the oldest returned project. No signatures, browser session cookies, or temporary login tokens are persisted.
Project API keys can be shared with collaborators. They authorize capture uploads and reads for their project. The project page in the Console always displays its key in a yellow box.
To import a key from another project owner without wallet login:
helios import-key hdbg_<key-from-project-page>
helios compile --project "Shared project" --helpImport validates the key, resolves the project name automatically, and merges it into the same configuration used by compilation and VS Code. Reimporting updates that project without duplicating it or removing other projects. Wallet login preserves imported projects belonging to other wallets.
For development, run pnpm test. node scripts/check-global-cli.mjs packs the package, installs it into an isolated npm global prefix, and checks executable discovery and equivalent compilation. The CLI portability workflow runs these checks on Windows, macOS, and Linux with Node 22 and 24. Publish the package only after the website and Worker with CLI-login support have been deployed.
Compile for a debugger project
helios login
helios compile --project "My project" --out-dir ./generated
# The compatibility command accepts the same option:
hl2ts --project "My project" --out-dir ./generated--project selects an exact configured project name and validates its key through GET /v1/project before writing output. Unknown names list all configured project names/IDs; an empty configuration explains how to run helios login. Duplicate names are rejected as ambiguous. Revoked keys, stale project metadata, and service outages stop compilation rather than generating a bundle with an unchecked key.
Generated JS/TS exports $debugger: {projectId,name,apiKey,endpoint,sources} and attaches it to each loaded validator/module. makeContractContextBuilder() carries that context onto the UPLC programs used by each validator's $hash.context.program, including source maps and unoptimized companions. Binding happens after cache lookup: changing projects does not reuse another project's credentials, and compilation caches remain credential-free. Written contract artifacts also preserve the context. Script CBOR and hashes are unchanged.
With the corresponding tx-utils release and ledger evaluation-observer support, spendWithRedeemer(), minting/staking methods, and attached programs automatically deliver failed builds to that project. No explicit makeDebuggerService() call is needed. makeTxBuilder({isMainnet, debugger:false}) disables automatic capture; an explicit debugger service overrides bundle configuration. Unannotated bundles retain their existing behavior.
The API key is intentionally embedded in generated bundles, including browser bundles, and grants upload and read access to that project's feed. Use project-specific keys appropriate for that distribution. The key is sent in the authorization header, not in capture payloads. Omitting --project embeds no debugger credentials.
Offline wallet generation
helios wallet create --network preprod prints JSON containing a cryptographically random 24-word recovery phrase and its base address. It does not contact a service. Supported networks are preprod (default), preview, and mainnet.
Use helios wallet create --network preprod --out wallet.json to write a new private file instead of printing the phrase. Existing files are never overwritten. The output phrase can be pasted into a demo’s ignored .env.local file.
Compilation context for captured failures
makeContractContextBuilder().build({isMainnet, parameters}) attaches credential-free $compilation metadata to validator programs and alternatives, even without --project. It records applicable parameter overrides as UPLC Data CBOR hex, the compiler/network, validator types/indices and exact dependency-hash inputs for both compilation passes. Source defaults remain in source. Caches and generated artifacts preserve this information without changing script CBOR.
To enable parameter-aware capture for an existing deployment, regenerate its JavaScript artifacts with the updated contract-utils and the original compiler version, asserting all deployed hashes using expectedHashes. Upgrade tx-utils and inject makeDebuggerService({apiKey}) into the transaction builder as usual. Merely upgrading tx-utils cannot recover build parameters from an older raw-CBOR bundle.
