> ## Documentation Index
> Fetch the complete documentation index at: https://ormilabs.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lookup Block By Timestamp

> Finds and retrieves the details of the closest block to a given timestamp. The lookup can be directed to find the block immediately before or after the specified time.



## OpenAPI

````yaml /open-api/0xapi.yaml get /v2/{chain_name}/blocks/by-timestamp/{timestamp}
openapi: 3.0.0
info:
  description: >-
    API for accessing blockchain data including tokens, NFTs, transactions,
    events, ENS, and blocks. Authentication is optional; providing an API key
    via Bearer token may grant higher rate limits or access to additional
    features.
  title: Ormi Data API
  version: v2
servers:
  - url: https://api.data.ormilabs.com
security:
  - OrmiApiKey: []
tags:
  - description: Operations related to fungible tokens and wallet balances.
    name: Tokens
  - description: Operations related to Non-Fungible Tokens (NFTs).
    name: NFTs
  - description: Operations related to blockchain transactions.
    name: Transactions
  - description: Operations related to smart contract events.
    name: Events
  - description: Operations related to blockchain blocks.
    name: Blocks
paths:
  /v2/{chain_name}/blocks/by-timestamp/{timestamp}:
    get:
      tags:
        - Blocks
      summary: Lookup Block By Timestamp
      description: >-
        Finds and retrieves the details of the closest block to a given
        timestamp. The lookup can be directed to find the block immediately
        before or after the specified time.
      operationId: lookupBlockByTimestamp
      parameters:
        - description: The Unix timestamp or ISO 8601 date string for block lookup.
          in: path
          name: timestamp
          required: true
          schema:
            example: '2023-11-07T05:31:56Z'
            format: date-time
            type: string
        - description: Direction to look for the block relative to the timestamp.
          in: query
          name: lookup_direction
          schema:
            default: before
            enum:
              - before
              - after
            type: string
        - $ref: '#/components/parameters/ChainNameParameter'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BlockDetailResponse'
          description: Successfully retrieved block details by timestamp.
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '429':
          $ref: '#/components/responses/RateLimitError'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    ChainNameParameter:
      description: The name or ID of the blockchain.
      in: path
      name: chain_name
      required: true
      schema:
        enum:
          - ethereum
          - apechain
          - arbitrum
          - avalanche
          - base
          - bsc
          - polygon
        example: ethereum
        type: string
  schemas:
    BlockDetailResponse:
      properties:
        block:
          $ref: '#/components/schemas/BlockItem'
      required:
        - block
      type: object
    BlockItem:
      properties:
        base_fee_per_gas:
          example: '10000000000'
          type: string
        difficulty:
          example: '0'
          type: string
        extra_data:
          example: 0x...
          type: string
        gas_limit:
          example: '30000000'
          type: string
        gas_used:
          example: '15000000'
          type: string
        hash:
          example: '0x2c9759ce3126199512631f50cb01e40717c880cb094a8974f62f100978fe7071'
          pattern: ^0x[a-fA-F0-9]{64}$
          type: string
        logs_bloom:
          example: 0x000...
          type: string
        miner:
          example: '0x312e67b47a2a29ae200184949093d92369f80b53'
          pattern: ^0x[a-fA-F0-9]{40}$
          type: string
        nonce:
          example: '0x0000000000000000'
          type: string
        number:
          example: 18000000
          format: int64
          type: integer
        parent_hash:
          example: '0x2c9759ce3126199512631f50cb01e40717c880cb094a8974f62f100978fe7071'
          pattern: ^0x[a-fA-F0-9]{64}$
          type: string
        receipt_root:
          example: 0x...
          type: string
        sha3_uncles:
          example: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
          type: string
        size:
          example: 100000
          format: int32
          type: integer
        state_root:
          example: 0x...
          type: string
        timestamp:
          example: '2023-11-07T05:31:56Z'
          format: date-time
          type: string
        total_difficulty:
          example: '58750003716598352816469'
          type: string
        transaction_count:
          example: 150
          format: int32
          type: integer
        transactions_root:
          example: 0x...
          type: string
        withdrawals_root:
          example: 0x...
          type: string
      required:
        - base_fee_per_gas
        - difficulty
        - extra_data
        - gas_limit
        - gas_used
        - hash
        - logs_bloom
        - miner
        - nonce
        - number
        - parent_hash
        - receipt_root
        - sha3_uncles
        - size
        - state_root
        - timestamp
        - total_difficulty
        - transaction_count
        - transactions_root
        - withdrawals_root
      type: object
    ApiError:
      properties:
        code:
          description: Internal application-specific error code.
          example: 20001
          type: integer
        data:
          additionalProperties: true
          description: Additional data related to the error, if applicable.
          example: {}
          type: object
        msg:
          description: A human-readable message providing more details about the error.
          example: Invalid API key provided.
          type: string
      required:
        - code
        - msg
      type: object
  responses:
    BadRequestError:
      content:
        application/json:
          examples:
            genericBadRequest:
              summary: Generic Bad Request
              value:
                code: 20101
                data: {}
                msg: Bad request. Please check your input.
            missingData:
              summary: Missing data
              value:
                code: 20301
                data: {}
                msg: Data missing. Please check your input.
            validationFailed:
              summary: Validation Failed
              value:
                code: 20201
                data:
                  errors:
                    - field: email
                      message: Email is not valid
                    - field: age
                      message: Age must be a positive number
                msg: Validation failed. Please check your input
          schema:
            $ref: '#/components/schemas/ApiError'
      description: >-
        Bad Request - The server cannot or will not process the request due to
        something that is perceived to be a client error (e.g., malformed
        request syntax, invalid request message framing, or deceptive request
        routing).
    UnauthorizedError:
      content:
        application/json:
          examples:
            invalidApiKey:
              summary: Invalid API Key
              value:
                code: 10005
                data: {}
                msg: Invalid API key provided.
            missingApiKey:
              summary: Missing API Key
              value:
                code: 10003
                data: {}
                msg: API key is missing from the Authorization header.
          schema:
            $ref: '#/components/schemas/ApiError'
      description: >-
        Unauthorized - The client request has not been completed because it
        lacks valid authentication credentials for the requested resource.
        Typically for an invalid or missing API key.
    RateLimitError:
      content:
        application/json:
          examples:
            rateLimited:
              summary: Rate Limit Exceeded
              value:
                code: 10020
                data:
                  retry_after_seconds: 60
                msg: Rate limit exceeded. Please try again later.
          schema:
            $ref: '#/components/schemas/ApiError'
      description: >-
        Too Many Requests - The user has sent too many requests in a given
        amount of time ("rate limiting").
    InternalServerError:
      content:
        application/json:
          examples:
            serverError:
              summary: Internal Server Error
              value:
                code: 20901
                data: {}
                msg: An unexpected internal server error occurred.
          schema:
            $ref: '#/components/schemas/ApiError'
      description: >-
        Internal Server Error - The server encountered an unexpected condition
        that prevented it from fulfilling the request.
  securitySchemes:
    OrmiApiKey:
      description: >
        Enter your API key in the format: Bearer <api_key>.

        Providing an API key may grant higher rate limits or access to
        additional features.

        The API will function without an API key for basic access.
      scheme: bearer
      type: http

````