What do the OpNum2Bin and OpBin2Num opcodes add to Kaspa scripts?

KIP-17 introduces two new opcodes to Kaspa's scripting system — OpNum2Bin and OpBin2Num — that let scripts convert between numbers and raw byte sequences. OpNum2Bin takes a number and a target byte size (up to 8 bytes) and encodes the number into exactly that many bytes in signed script-number format; the chosen size must be large enough to hold the value. OpBin2Num works in reverse: it reads a byte sequence and pushes back the smallest valid numeric encoding of that value, subject to the same 8-byte limit. Together they give script authors a clean, spec-defined path between numeric values and binary data — something that previously required awkward workarounds. Developers building contracts or KRC-20 token logic on Kaspa can use these opcodes for reliable numeric-to-binary conversions, making scripts more compact and less error-prone.

Learn more ›