v0.14.02026-10-06
This release contains several breaking changes, please refer to the migration notes for more information.
cashc compiler
- :sparkles: Add support for user-defined reusable functions, including multiple return values.
- :sparkles: Add support for top-level global constants, including simple arithmetic / concatenation operations.
- :sparkles: Add support for import directives to share user-defined functions across files, including imports from node_modules.
- :sparkles: Add support for reassigning existing variables in tuple destructuring (e.g. (a, b) = swap(a, b)), optionally mixed with fresh declarations.
- :sparkles: Add unused modifier for parameters or variables that are intentionally unused.
- :hammerandwrench: Update compileString to take an optional files object for filesystem-free import resolution.
- :hammerandwrench: Unused variables that are not marked unused now produce a compiler warning instead of a compilation error.
- :hammerandwrench: Add a compiler warning for values assigned to a variable that are never read afterwards.
- :bug: Fix bug where date literals were parsed in the local time zone instead of UTC.
- :bug: BREAKING: Fix bug where LockingBytecodeNullData used incorrect push opcodes for empty chunks and chunks of 128-255 bytes, so it did not match the SDK's addOpReturnOutput().
- :bug: BREAKING: Fix bug where hex literals with an odd number of digits (e.g. 0x123) compiled to a different value (0x1203). They now cause a compile error.
- :bug: Fix bug where using the same variable in both arguments of .slice() could fail to compile.
- :bug: Fix bug where a variable reassigned in a for loop's init (e.g. for (i = 0; ...)) had an incorrect value after the loop.
- :bug: Fix bug where console.log showed an outdated value for a reassigned variable after its final use.
- :racehorse: Add new optimisations for loop counter updates, reassignments, scope cleanup, stack shuffles, and order-independent operations.
- :racehorse: Greatly improve compiler speed for very large contracts.
CashScript SDK
- :sparkles: Add support for debugging user-defined functions, including stack traces for nested functions.
- :sparkles: Add a validateTransactions option (default: true) to the MockNetworkProvider to validate sent transactions against the BCH VM.
- :boom: BREAKING: Remove generateLockingBytecode() from the Unlocker interface.
- :hammerandwrench: BREAKING: The TransactionBuilder now requires UTXOs to include their lockingBytecode, and validates it against the provided unlocker.
- :hammerandwrench: BREAKING: Replace the SignatureTemplate's getHashType(), getPublicKey() and getSignatureAlgorithm() methods with the sighashType, publicKey and signatureAlgorithm properties.
- :hammerandwrench: BREAKING: Remove the bchForkId parameter from SignatureTemplate's generateSignature() method, since BCH consensus rules always require the fork ID flag.
- :hammerandwrench: BREAKING: Rename the HashType enum to SighashType.
- :hammerandwrench: Add lockingBytecode field to the Utxo interface, set automatically on all UTXOs returned by network providers.
- :hammerandwrench: MockNetworkProvider now logs a warning instead of throwing when the same transaction is sent twice.
- :hammerandwrench: ElectrumNetworkProvider now uses Electrum protocol 1.5.0 (was 1.4.1), and getBlockHeight() no longer subscribes to new headers. Custom electrum clients should negotiate 1.5.0 or later.
- :hammerandwrench: Update @electrum-cash/network to 4.4.0. In a browser, the ElectrumNetworkProvider now disconnects while the page is hidden and reconnects afterwards, restoring any subscriptions (see Browser visibility and connectivity).
- :hammerandwrench: Make cashscript/vitest types compatible with Vitest 5.
- :bug: Fix bug where invalid hex string arguments were silently encoded to different bytes.
- :bug: Fix bug where pubkey arguments were not checked to be 33 or 65 bytes.
- :bug: Fix bug in ElectrumNetworkProvider automatic connection management.
- :bug: Fix bug where send() threw a FailedTransactionError when the transaction was broadcast but could not be retrieved afterwards.
- :bug: Fix bug where debugging reported a VM resource limit as a failed require statement.
- :bug: Fix minimum fee check rounding bug.
- :bug: Fix bug where setLocktime() accepted invalid values.
- :bug: Fix edge case bug where a failing final require(variable) statement was reported incorrectly in debugging.
v0.14.0-next.7预发布2026-09-30
cashc 编译器这版修了几处会产出错误结果的编译问题:.slice() 两个参数使用同一变量时可能编译失败或生成错误代码;for 循环初始化语句中被重新赋值的变量,循环结束后取值不对;LockingBytecodeNullData 遇到超过 255 字节的数据块会静默输出错误结果,现在会直接报错。另外补充了作用域清理、栈元素调整以及深层变量自增自减的优化,编译产物更紧凑。
CashScript SDK 主要改进调试体验:此前调试器会把虚拟机资源耗尽误报成 require 断言失败,容易误导排查方向;部分含嵌套作用域的合约调试时直接失败,也一并修复了。
v0.14.0-next.6预发布2026-09-28
cashc 编译器:两处破坏性变更——产物的 debug.sources 现在只存一次导入的源文件,产物可用 compileString 重新编译;compileString 的 files 选项改用 package: 前缀作为键名。此外禁止绝对路径导入和重复引入同一包。修复了符号链接包(如 pnpm)导入解析不正确、compileFile 与 compileString 解析行为不一致、LockingBytecodeNullData 部分数据块大小下推送 opcode 用错、奇数位十六进制字面量编译结果有误等问题;针对循环计数器更新、循环内重新赋值及顺序无关操作也做了优化。
CashScript SDK:ElectrumNetworkProvider 升级到 Electrum 协议 1.5.0,@electrum-cash/network 更新至 4.4.0(页面隐藏时自动断开连接),cashscript/vitest 类型兼容 Vitest 5。修复方面,无效十六进制字符串不再被静默转换,pubkey 参数会校验 33 或 65 字节长度,同时解决了自动连接管理、最小手续费取整、setLocktime() 接受非法值、末尾 require 失败时报错不准等 bug。
v0.14.0-next.5预发布2026-09-15
cashc 编译器
元组解构中新声明的目标现在可以使用 constant 和 unused 修饰符。未加 unused 标记的未使用变量不再直接报错,而是降级为编译警告,可通过 console.warn 输出或交给新增的 warningListener 选项处理;变量被赋值后从未读取的情况也会给出类似提醒。另外修复了日期字面量解析随浏览器地区设置变化的问题,现已统一按 UTC 处理;超大合约的编译速度也有明显提升。
CashScript SDK
MockNetworkProvider 新增 validateTransactions 选项(默认开启),发送交易时会对照 BCH VM 校验;重复提交已见交易改为警告而非报错。网络提供商返回的所有 UTXO 都会自动带上 lockingBytecode 字段。注意两处破坏性变更:TransactionBuilder 要求 UTXO 必须包含 lockingBytecode 并与解锁器校验一致;Unlocker 接口中的 generateLockingBytecode() 已被移除,升级时需要调整相应调用。
v0.13.32026-09-15
CashScript SDK 本次发布只有一个修复:当使用 placeholderP2PKHUnlocker() 构造占位解锁脚本时,getTransactionSize() 会低估输入占用的字节数,导致预估交易体积偏小。此前若依赖该方法做交易大小估算或手续费计算,可能因输入尺寸不足而估算偏差;现在估算结果已与实际序列化后的输入大小一致。
v0.14.0-next.4预发布2026-08-20
cashc 编译器
包内导入现在会从 nodemodules 解析(如 import "pkg/math.cash"),合约库终于可以按 npm 包的形式分发安装了。元组解构支持给已有变量重新赋值,例如 (a, b) = swap(a, b),也可与新变量声明混用。另外新增了 OPNOT OP_NOT 的折叠优化,能略微缩减合约体积。
CashScript SDK
本次有三处破坏性变更,升级时需要同步调整代码:SignatureTemplate 的 getHashType()、getPublicKey()、getSignatureAlgorithm() 三个方法改为 sighashType、publicKey、signatureAlgorithm 属性直接读取;generateSignature() 移除了 bchForkId 参数——BCH 共识规则本来就强制携带 fork ID,无需再手动传入;枚举 HashType 更名为 SighashType,与签名场景的语义保持一致。
v0.14.0-next.3预发布2026-07-30
cashc 编译器这次放宽了全局常量的写法,可以直接在定义里做简单的算术和字符串拼接运算,不必再手工算好结果填进去。另外新增了 unused 修饰符,可以标注那些故意不使用的参数或变量,避免编译器误报,代码意图也更清楚。
CashScript SDK 方面,调试嵌套函数里 require 断言失败时,现在会输出调用栈回溯,层层嵌套的校验逻辑出错时能直接定位到是哪一层抛的条件失败,省去逐层排查的麻烦。
v0.14.0-next.2预发布2026-07-23
cashc 编译器这次在语言能力上补了两块:一是支持在顶层定义全局常量,不必再绕道函数;二是自定义函数可以返回多个值,并在调用处直接解构接收,少写几行取值代码。
编译产物也做了瘦身:全局函数与常量在不比 OPDEFINE/OPINVOKE 更大的情况下会被内联,热点调用能省一次跳转。
v0.14.0-next.1预发布2026-07-07
cashc 编译器方面,compileString 现在接受一个可选的 files 对象,导入解析不再依赖文件系统,便于在浏览器等环境中使用;同时新增 OPSWAP OPMUL 指令序列优化,生成的合约更精简。CashScript SDK 则加入了对用户自定义函数的调试支持,排查合约逻辑时可以逐层跟踪到自己写的函数内部。
v0.14.0-next.0预发布2026-06-26
⚠️ 本版本为预发布版,尚不稳定,后续预发布仍可能对 API 与编译产物做出不兼容调整。
cashc 编译器
这版最大的变化是函数可以自己写了:用户现在能定义可复用的自定义函数,并在编译中直接调用,不必再把逻辑重复展开到每处使用的地方。配合新增的 import 指令,同一项目里的多个文件还能共享这些函数定义,跨文件组织合约逻辑首次成为可能。对使用者来说,合约源码的模块化程度明显提升,维护成本也会随之下降。