Little module for directlty composing bitcoin scripts and compiling to byte code.
npm i btc-script-builder
var Script =var myScript =// lets make a 2-of-2 multisig scriptconst scriptBuf = myScript
script = new Script()
Instantiate a new script builder.
Push an opcode to the stack.
op should be passed as a string and does not have to be prefixed with 'OP_'. For
2 <= n <= 16,
n may be passed as a decimal number, string or as the string
Push some data onto the stack.
data may be passed as a hex-encoded string or directly as a
In many cases, we may wish to simply encode some assembly directly. In this caase, the assembly script may be passed as a
string and it shall be parsed into a stack.
var buf = script.compile([buf, offset])
Compile the current stack into bytecode in
buf starting at
offset. Shall return a new
buffer if none is provided.
n items from the top of the stack. Returns the
Empty the current stack.
var len = script.encodingLength()
Returns the length of the bytecode corresponding to the current stack.