Util#

class defichain.node.Util(node)#
createmultisig(nrequired: int, keys: [<class 'str'>], address_type: str = 'legacy') {}#

Creates a multi-signature address with n signature of m keys required. It returns a json object with the address and redeemScript.

Parameters:
  • nrequired (int) – (required) The number of required signatures out of the n keys

  • keys (json array) – (required) A json array of hex-encoded public keys

  • address_type (str) – (optional) The address type to use. Options are “legacy”, “p2sh-segwit”, and “bech32”

Returns:

{…} (json) – returns a json object with the address and redeemScript

{
    "address":"multisigaddress",  (string) The value of the new multisig address.
    "redeemScript":"script"       (string) The string value of the hex-encoded redemption script.
}

Example:
>>> node.util.createmultisig(2, ["03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd", "03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626"])
deriveaddresses(descriptor: str, range: int | None = None) [<class 'str'>]#

Derives one or more addresses corresponding to an output descriptor.

Examples of output descriptors are:

pkh(<pubkey>) P2PKH outputs for the given pubkey

wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey

sh(multi(<n>,<pubkey>,<pubkey>,…)) P2SH-multisig outputs for the given threshold and pubkeys

raw(<hex script>) Outputs whose scriptPubKey equals the specified hex scripts

In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one or more path elements separated by “/”, where “h” represents a hardened child key.

For more information on output descriptors, see the documentation in the doc/descriptors.md file.

Parameters:
  • descriptor (str) – (required) The descriptor

  • range (int or array) – (optional) If a ranged descriptor is used, this specifies the end or the range (in [begin,end] notation) to derive

Returns:

[…] (array) – the derived addresses

Example:
>>> node.util.deriveaddresses("wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#cjjspncu", [0,2])
estimatesmartfee(conf_target: int, estimate_mode: str = 'CONSERVATIVE') {}#

Estimates the approximate fee per kilobyte needed for a transaction to begin confirmation within conf_target blocks if possible and return the number of blocks for which the estimate is valid. Uses virtual transaction size as defined in BIP 141 (witness data is discounted).

Parameters:
  • conf_target (int) – (required) Confirmation target in blocks (1 - 1008)

  • estimate_mode (str) –

    (optional) The fee estimate mode. Whether to return a more conservative estimate which also satisfies a longer history. A conservative estimate potentially returns a higher feerate and is more likely to be sufficient for the desired target, but is not as responsive to short term drops in the prevailing fee market.

    Must be one of:

    ”UNSET”

    ”ECONOMICAL”

    ”CONSERVATIVE”

Returns:

{…} (json) – resturns a estimation of a fee

{
  "feerate" : x.x,     (numeric, optional) estimate fee rate in DFI/kB
  "errors": [ str... ] (json array of strings, optional) Errors encountered during processing
  "blocks" : n         (numeric) block number where estimate was found
}

The request target will be clamped between 2 and the highest target fee estimation is able to return based on how long it has been running.

An error is returned if not enough transactions and blocks have been observed to make an estimate for any number of blocks.

Example:
>>> node.util.estimatesmartfee(6)
getdescriptorinfo(descriptor: str) {}#

Analyses a descriptor

Parameters:

descriptor (str) – (required) The descriptor

Returns:

{…} (json) – returns information about decriptor

{
    "descriptor" : "desc",         (string) The descriptor in canonical form, without private keys
    "checksum" : "chksum",         (string) The checksum for the input descriptor
    "isrange" : true|false,        (boolean) Whether the descriptor is ranged
    "issolvable" : true|false,     (boolean) Whether the descriptor is solvable
    "hasprivatekeys" : true|false, (boolean) Whether the input descriptor contained at least one private key
}

Example:
>>> node.util.getdescriptorinfo("wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)")
signmessagewithprivkey(privkey: str, message: str) str#

Sign a message with the private key of an address

Parameters:
  • privkey (str) – (required) The private key to sign the message with

  • message (str) – (required) The message to create a signature of

Returns:

“signature” (string) – The signature of the message encoded in base 64

Example:
>>> node.util.signmessagewithprivkey("privkey", "my message")
validateaddress(address: str) {}#

Return information about the given defi address

Parameters:

address (str) – (required) The defi address to validate

Returns:

{…} (json) – Return information about the given defi address

{
  "isvalid" : true|false,       (boolean) If the address is valid or not. If not, this is the only property returned.
  "address" : "address",        (string) The defi address validated
  "scriptPubKey" : "hex",       (string) The hex-encoded scriptPubKey generated by the address
  "isscript" : true|false,      (boolean) If the key is a script
  "iswitness" : true|false,     (boolean) If the address is a witness address
  "witness_version" : version   (numeric, optional) The version number of the witness program
  "witness_program" : "hex"     (string, optional) The hex value of the witness program
}

Example:
>>> node.util.validateaddress("df1qduwqfyhz0n0duvmudlhmyx2uzk4u2xqmn627zr")
verifymessage(address: str, signature: str, message: str) bool#

Verify a signed message

Parameters:
  • address (str) – (required) The defi address to use for the signature

  • signature (str) – (required) The signature provided by the signer in base 64 encoding (see signmessage)

  • message (str) – (required) The message that was signed

Returns:

bool – If the signature is verified or not

Example:
>>> node.util.verifymessage("df1qduwqfyhz0n0duvmudlhmyx2uzk4u2xqmn627zr", "signature", "my message")