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:
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 astring
.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 thrownError
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 usingassertSuccess
to simplify error handling: