sCrypt TypeScript Transpiler

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

Transpiler that compiles TypeScript smart contracts for Bitcoin SV into sCrypt bytecode. Current stable version is 1.2.29, updated periodically. Key differentiator: enables writing Bitcoin smart contracts entirely in TypeScript, leveraging its tooling and type safety, while outputting efficient on-chain bytecode. Requires TypeScript ~5.3.0 as a peer dependency and Node.js >=16.

error Error: Cannot find module 'scrypt-ts-transpiler'
cause Package is not installed or not in node_modules.
fix
Run: npm install scrypt-ts-transpiler
error SyntaxError: The requested module 'scrypt-ts-transpiler' does not provide an export named 'transpile'
cause Using CommonJS require instead of ESM import.
fix
Use import statement: import { transpile } from 'scrypt-ts-transpiler'
error error TS2688: Cannot find type definition file for 'scrypt-ts-transpiler'
cause TypeScript cannot resolve the package's types; likely missing or misconfigured.
fix
Ensure TypeScript ~5.3.0 is installed and tsconfig.json includes 'moduleResolution': 'node' or 'node16'.
breaking Version 1.0.0 changed the transpile function signature; options object is required.
fix Pass an options object as the second argument to transpile().
gotcha TypeScript peer dependency must be exactly ~5.3.x; other versions may cause compilation errors.
fix Install TypeScript ~5.3.0: npm install typescript@~5.3.0
gotcha Node.js <16 is not supported; transpile will fail on older runtimes.
fix Upgrade Node.js to >=16.
npm install scrypt-ts-transpiler
yarn add scrypt-ts-transpiler
pnpm add scrypt-ts-transpiler

Compile a simple sCrypt TypeScript smart contract into bytecode and save the artifact.

import { transpile } from 'scrypt-ts-transpiler';
import { writeFileSync } from 'fs';

const source = `
export class Counter extends SmartContract {
    @prop()
    readonly count: bigint;

    constructor(count: bigint) {
        super(...arguments);
        this.count = count;
    }

    @method()
    public increment() {
        this.count++;
    }
}`;

const result = transpile(source, {
    artifactPath: './artifacts',
    sourceMap: true
});

writeFileSync('artifacts/counter.scrypt', result.bytecode);
console.log('Bytecode compiled successfully');