Class: Script

Script

new Script(from)

A bitcoin transaction script. Each transaction's inputs and outputs has a script that is evaluated to validate it's spending.

See https://en.bitcoin.it/wiki/Script

Parameters:
Name Type Argument Description
from Object | string | Buffer <optional>

optional data to populate script

Source:

Methods

<static> buildDataOut(to)

Parameters:
Name Type Description
to string | Buffer

the data to embed in the output

Source:
Returns:

a new OP_RETURN script with data

<static> buildMultisigOut(pubkeys, m, opts)

Parameters:
Name Type Argument Description
pubkeys Array.<PublicKey>

list of all public keys controlling the output

m number

amount of required signatures to spend the output

opts Object <optional>

Several options:

   - noSorting: defaults to false, if true, don't sort the given
                 public keys before creating the script
Source:
Returns:

a new Multisig output script for given public keys, requiring m of those public keys to spend

<static> buildP2SHMultisigIn(pubkeys, threshold, signatures, opts)

A new P2SH Multisig input script for the given public keys, requiring m of those public keys to spend

Parameters:
Name Type Argument Description
pubkeys Array.<PublicKey>

list of all public keys controlling the output

threshold number

amount of required signatures to spend the output

signatures Array

signatures to append to the script

opts Object <optional>
Properties
Name Type Argument Description
noSorting boolean <optional>

don't sort the given public keys before creating the script (false by default)

cachedMultisig Script <optional>

don't recalculate the redeemScript

Source:
Returns:

Script

<static> buildPublicKeyHashIn(publicKey, signature, sigtype)

Builds a scriptSig (a script for an input) that signs a public key hash output script.

Parameters:
Name Type Argument Description
publicKey Buffer | string | PublicKey
signature Buffer

the signature in DER cannonical encoding

sigtype number <optional>

the type of the signature (defaults to SIGHASH_ALL)

Source:

<static> buildPublicKeyHashOut(to)

Parameters:
Name Type Description
to Address | PublicKey

destination address or public key

Source:
Returns:

a new pay to public key hash output for the given address or public key

<static> buildPublicKeyOut()

Source:
Returns:

a new pay to public key output for the given public key

<static> buildScriptHashOut(script)

Parameters:
Name Type Description
script Script

the redeemScript for the new p2sh output

Source:
Returns:

Script new pay to script hash script for given script

<static> empty()

Source:
Returns:

Script an empty script

<static> fromAddress()

Source:
Returns:

Script a script built from the address

add(obj) → {Script}

Adds a script element to the end of the script.

Parameters:
Name Type Description
obj *

a string, number, Opcode, Bufer, or object to add

Source:
Returns:

this script instance

Type
Script

classify() → {object}

Source:
Returns:

The Script type if it is a known form, or Script.UNKNOWN if it isn't

Type
object

equals()

Compares a script with another script

Source:

isDataOut()

Source:
Returns:

true if this is an OP_RETURN data script

isMultisigIn()

Source:
Returns:

true if this is a multisig input script

isMultisigOut()

Source:
Returns:

true if this is a mutlsig output script

isPublicKeyHashIn()

Source:
Returns:

true if this is a pay to public key hash input script

isPublicKeyHashOut()

Source:
Returns:

true if this is a pay to pubkey hash output script

isPublicKeyIn()

Source:
Returns:

true if this is a pay to public key input script

isPublicKeyOut()

Source:
Returns:

true if this is a public key output script

isPushOnly()

Source:
Returns:

true if the script is only composed of data pushing opcodes or small int opcodes (OP_0, OP_1, ..., OP_16)

isScriptHashIn()

Source:
Returns:

true if this is a p2sh input script Note that these are frequently indistinguishable from pubkeyhashin

isScriptHashOut()

Source:
Returns:

true if this is a p2sh output script

isStandard()

Source:
Returns:

true if script is one of the known types

prepend(obj) → {Script}

Adds a script element at the start of the script.

Parameters:
Name Type Description
obj *

a string, number, Opcode, Bufer, or object to add

Source:
Returns:

this script instance

Type
Script

toScriptHashOut()

Source:
Returns:

Script a new pay to script hash script that pays to this script