Class: Address

primitives~Address(optionsnullable)

Address Represents an address.

Constructor

new Address(optionsnullable)

Create an address.

Parameters:
Name Type Attributes Description
options Object <nullable>
Properties:
Name Type Description
hash Buffer
type AddressPrefix
version Number
Source:

Members

(static) types :Number

Address types.

Type:
  • Number
Properties:
Name Type Description
PUBKEYHASH Number
SCRIPTHASH Number
WITNESS Number
Source:

(static, constant) typesByVal :Object

Address types by value.

Type:
  • Object
Source:

Methods

(static) fromBase58(data, networknullable) → {Address}

Create an address object from a base58 address.

Parameters:
Name Type Attributes Description
data AddressString
network Network <nullable>
Source:
Throws:

Parse error.

Returns:
Type
Address

(static) fromBech32(data, networknullable) → {Address}

Create an address object from a bech32 address.

Parameters:
Name Type Attributes Description
data String
network Network <nullable>
Source:
Throws:

Parse error.

Returns:
Type
Address

(static) fromHash(hash, type, versionopt) → {Address}

Create a naked address from hash/type/version.

Parameters:
Name Type Attributes Default Description
hash Hash
type AddressPrefix
version Number <optional>
-1
Source:
Throws:

on bad hash size

Returns:
Type
Address

(static) fromInputScript(script) → {Address|null}

Create an Address from an input script. Attempt to extract address properties from an input script.

Parameters:
Name Type Description
script Script
Source:
Returns:
Type
Address | null

(static) fromOptions(options) → {Address}

Insantiate address from options.

Parameters:
Name Type Description
options Object
Source:
Returns:
Type
Address

(static) fromProgram(version, hash) → {Address}

Instantiate address from witness program.

Parameters:
Name Type Description
version Number
hash Buffer
Source:
Returns:
Type
Address

(static) fromPubkeyhash(hash) → {Address}

Instantiate address from pubkeyhash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

(static) fromRaw(data) → {Address}

Create an address object from a serialized address.

Parameters:
Name Type Description
data Buffer
Source:
Throws:

Parse error.

Returns:
Type
Address

(static) fromScript(script) → {Address|null}

Create an Address from an output script. Parse an output script and extract address properties. Converts pubkey and multisig scripts to pubkeyhash and scripthash addresses.

Parameters:
Name Type Description
script Script
Source:
Returns:
Type
Address | null

(static) fromScripthash(hash) → {Address}

Instantiate address from scripthash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

(static) fromString(addr, networknullable) → {Address}

Instantiate address from string.

Parameters:
Name Type Attributes Description
addr String
network Network | NetworkType <nullable>
Source:
Returns:
Type
Address

(static) fromWitness(witness) → {Address|null}

Create an Address from a witness. Attempt to extract address properties from a witness.

Parameters:
Name Type Description
witness Witness
Source:
Returns:
Type
Address | null

(static) fromWitnessPubkeyhash(hash) → {Address}

Instantiate address from witness pubkeyhash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

(static) fromWitnessScripthash(hash) → {Address}

Instantiate address from witness scripthash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

(static) getHash(data, encnullable) → {Hash}

Get the hash of a base58 address or address-related object.

Parameters:
Name Type Attributes Description
data String | Address | Hash
enc String <nullable>

Can be "hex" or null.

Source:
Returns:
Type
Hash

(static) getType(prefix, network) → {AddressType}

Get an address type for a specified network address prefix.

Parameters:
Name Type Description
prefix Number
network Network
Source:
Returns:
Type
AddressType

equals(addr) → {Boolean}

Test equality against another address.

Parameters:
Name Type Description
addr Address
Source:
Returns:
Type
Boolean

(private) fromBase58(data, networknullable)

Inject properties from base58 address.

Parameters:
Name Type Attributes Description
data AddressString
network Network <nullable>
Source:
Throws:

Parse error

(private) fromBech32(data, networknullable)

Inject properties from bech32 address.

Parameters:
Name Type Attributes Description
data String
network Network <nullable>
Source:
Throws:

Parse error

(private) fromHash(hash, type, versionopt)

Inject properties from a hash.

Parameters:
Name Type Attributes Default Description
hash Buffer | Hash
type AddressPrefix
version Number <optional>
-1
Source:
Throws:

on bad hash size

(private) fromInputScript(script)

Inject properties from input script.

Parameters:
Name Type Description
script Script
Source:

(private) fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options Object
Source:

(private) fromProgram(version, hash) → {Address}

Inject properties from witness program.

Parameters:
Name Type Description
version Number
hash Buffer
Source:
Returns:
Type
Address

(private) fromPubkeyhash(hash) → {Address}

Inject properties from pubkeyhash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

(private) fromRaw(data)

Inject properties from serialized data.

Parameters:
Name Type Description
data Buffer
Source:
Throws:

Parse error

(private) fromScript(script)

Inject properties from output script.

Parameters:
Name Type Description
script Script
Source:

(private) fromScripthash(hash) → {Address}

Inject properties from scripthash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

(private) fromString(addr, networknullable) → {Address}

Inject properties from string.

Parameters:
Name Type Attributes Description
addr String
network Network | NetworkType <nullable>
Source:
Returns:
Type
Address

(private) fromWitness(witness)

Inject properties from witness.

Parameters:
Name Type Description
witness Witness
Source:

(private) fromWitnessPubkeyhash(hash) → {Address}

Inject properties from witness pubkeyhash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

(private) fromWitnessScripthash(hash) → {Address}

Inject properties from witness scripthash.

Parameters:
Name Type Description
hash Buffer
Source:
Returns:
Type
Address

getHash(encnullable) → {Hash|Buffer}

Get the address hash.

Parameters:
Name Type Attributes Description
enc String <nullable>

Can be "hex" or null.

Source:
Returns:
Type
Hash | Buffer

getPrefix(networknullable) → {Number}

Get a network address prefix for the address.

Parameters:
Name Type Attributes Description
network Network <nullable>
Source:
Returns:
Type
Number

getSize() → {Number}

Calculate size of serialized address.

Source:
Returns:
Type
Number

getType() → {String}

Get the address type as a string.

Source:
Returns:
Type
String

inspectSymbol() → {Object}

Inspect the Address.

Source:
Returns:
Type
Object

isNull() → {Boolean}

Test whether the address is null.

Source:
Returns:
Type
Boolean

isProgram() → {Boolean}

Test whether the address is a witness program.

Source:
Returns:
Type
Boolean

isPubkeyhash() → {Boolean}

Test whether the address is pubkeyhash.

Source:
Returns:
Type
Boolean

isScripthash() → {Boolean}

Test whether the address is scripthash.

Source:
Returns:
Type
Boolean

isUnknown() → {Boolean}

Test whether the address is an unknown witness program.

Source:
Returns:
Type
Boolean

isWitnessPubkeyhash() → {Boolean}

Test whether the address is witness pubkeyhash.

Source:
Returns:
Type
Boolean

isWitnessScripthash() → {Boolean}

Test whether the address is witness scripthash.

Source:
Returns:
Type
Boolean

toBase58({{NetworkType|Network)?}) → {AddressString}

Compile the address object to a base58 address.

Parameters:
Name Type Description
{{NetworkType|Network)?}

network

Source:
Throws:

Error on bad hash/prefix.

Returns:
Type
AddressString

toBech32({{NetworkType|Network)?}) → {String}

Compile the address object to a bech32 address.

Parameters:
Name Type Description
{{NetworkType|Network)?}

network

Source:
Throws:

Error on bad hash/prefix.

Returns:
Type
String

toRaw({{NetworkType|Network)?}) → {Buffer}

Compile the address object to its raw serialization.

Parameters:
Name Type Description
{{NetworkType|Network)?}

network

Source:
Throws:

Error on bad hash/prefix.

Returns:
Type
Buffer

toString(networknullable) → {AddressString}

Convert the Address to a string.

Parameters:
Name Type Attributes Description
network Network | NetworkType <nullable>
Source:
Returns:
Type
AddressString