CCC Docs
    Preparing search index...

    Hierarchy

    Index

    Constructors

    • Construct a new Epoch.

      The constructor enforces a positive denominator. If denominator is non-positive an Error is thrown.

      Parameters

      • integer: bigint

        Whole number portion of the epoch.

      • numerator: bigint

        Fractional numerator.

      • denominator: bigint

        Fractional denominator (must be > 0).

      Returns Epoch

    Properties

    integer: bigint

    Whole number portion of the epoch.

    numerator: bigint

    Fractional numerator.

    denominator: bigint

    Fractional denominator (must be > 0).

    byteLength?: number

    The bytes length of the entity, if it is fixed, otherwise undefined

    Accessors

    • get "0"(): bigint

      Returns bigint

      use integer instead Backwards-compatible array-style index 0 referencing the whole epoch integer.

    • get "1"(): bigint

      Returns bigint

      use numerator instead Backwards-compatible array-style index 1 referencing the epoch fractional numerator.

    • get "2"(): bigint

      Returns bigint

      use denominator instead Backwards-compatible array-style index 2 referencing the epoch fractional denominator.

    Methods

    • Create an Epoch from an EpochLike value.

      Accepts:

      • an Epoch instance (returned as-is)
      • an object { integer, numerator, denominator } where each field is NumLike
      • a tuple [integer, numerator, denominator] where each element is NumLike

      All returned fields are converted to Num using numFrom.

      Parameters

      • epochLike: EpochLike

        Value to convert into an Epoch.

      Returns Epoch

      A new or existing Epoch instance.

    • Return an epoch representing one cycle (180 + 0/1).

      This is a NervosDAO convenience constant.

      Returns Epoch

    • Compare this epoch to another EpochLike.

      Comparison is performed by converting both epochs to a common integer representation: (integer * denominator + numerator) scaled by the other's denominator.

      Parameters

      • other: EpochLike

        EpochLike value to compare against.

      Returns -1 | 0 | 1

      1 if this > other, 0 if equal, -1 if this < other.

    • Check equality with another EpochLike.

      Parameters

      • other: EpochLike

        EpochLike to test equality against.

      Returns boolean

      true if both epochs represent the same value.

    • Return a normalized epoch:

      • Ensures numerator is non-negative by borrowing from integer if needed.
      • Reduces the fraction (numerator/denominator) by their GCD.
      • Carries any whole units from the fraction into integer.

      Returns Epoch

      A new, normalized Epoch instance.

    • Add another epoch to this one.

      If denominators differ, the method aligns to a common denominator before adding the fractional numerators, then returns a normalized Epoch.

      Parameters

      Returns Epoch

      New Epoch equal to this + other.

    • Convert this epoch to an estimated Unix timestamp in milliseconds using as reference the block header.

      Parameters

      • reference: ClientBlockHeader

        ClientBlockHeader providing a reference epoch and timestamp.

      Returns bigint

      Unix timestamp in milliseconds as bigint.

    • Encode the entity into bytes

      Parameters

      Returns Bytes

      The encoded bytes

      Will throw an error if the entity is not serializable

    • Decode the entity from bytes

      Parameters

      Returns Epoch

      The decoded entity

      Will throw an error if the entity is not serializable

    • Create an entity from bytes

      Parameters

      Returns Epoch

      The created entity

      Will throw an error if the entity is not serializable

    • Convert the entity to bytes

      Returns Bytes

      The bytes representation of the entity

    • Create a clone of the entity

      Returns Epoch

      A clone of the entity

    • Calculate the hash of the entity

      Returns `0x${string}`

      The hash of the entity

    • Convert the entity to Hex

      Returns `0x${string}`

      The hexadecimal representation of the entity