Function lockingBytecodeToCashAddress

  • Encode a locking bytecode as a CashAddress.

    If bytecode matches a standard pattern, it is encoded using the proper address type and returned as a CashAddressResult.

    If bytecode cannot be encoded as an address (i.e. because the pattern is not standard), an error message is returned as a string.

    For the reverse, see cashAddressToLockingBytecode.

    Due to the high likelihood of runtime errors in a variety of use cases (e.g. attempting to convert P2PK or arbitrary data outputs to CashAddresses for display in a transaction viewer or block explorer), this function returns encoding errors in a type-safe way (as a string) rather than via thrown Error objects.

    For applications in which the input to lockingBytecodeToCashAddress is trusted (e.g. the application is encoding an address for self-generated locking bytecode), consider using assertSuccess to simplify error handling:

    import {
    assertSuccess,
    lockingBytecodeToCashAddress
    } from '@bitauth/libauth';
    import { lockingBytecode, useTheAddress } from './my/app.js';

    const { address } = assertSuccess(
    lockingBytecodeToCashAddress(lockingBytecode)
    );

    useTheAddress(address);

    Parameters

    • __namedParameters: Omit<DecodedCashAddressLockingBytecode, "prefix" | "tokenSupport"> & {
          prefix?: "bitcoincash" | "bchtest" | "bchreg";
          tokenSupport?: boolean;
      }

    Returns string | CashAddressResult

Generated using TypeDoc