{
    "openapi": "3.0.2",
    "info": {
        "title": "FindBlock",
        "version": "0.1",
        "description": "EVM blockchain metadata API for finding block by timestamp & proxying RPC requests to 1k+ EVM blockchains.",
        "contact": {
            "url": "https://findblock.xyz",
            "email": "gm@0xlabs.xyz",
            "name": "0xLabs"
        }
    },
    "servers": [{ "url": "/v1", "description": "Production" }],
    "paths": {
        "/chain": {
            "get": {
                "description": "Get a list of all available chains",
                "tags": ["chains"],
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "array",
                                    "items": {
                                        "$ref": "#/components/schemas/Chain"
                                    }
                                }
                            }
                        }
                    },
                    "500": {
                        "$ref": "#/components/responses/500"
                    }
                }
            }
        },
        "/chain/{chainId}": {
            "get": {
                "description": "Get chain information by Chain ID",
                "tags": ["chains"],
                "parameters": [
                    {
                        "$ref": "#/components/parameters/ChainId"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Chain"
                                }
                            }
                        }
                    },
                    "400": {
                        "$ref": "#/components/responses/400"
                    },
                    "404": {
                        "$ref": "#/components/responses/404"
                    },
                    "500": {
                        "$ref": "#/components/responses/500"
                    }
                }
            }
        },
        "/chain/{chainId}/rpc/use": {
            "post": {
                "description": "Forwards a RPC request to the best performing RPC",
                "tags": ["rpc"],
                "parameters": [
                    {
                        "$ref": "#/components/parameters/ChainId"
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/JsonRpcRequest"
                            },
                            "examples": {
                                "block": {
                                    "value": {
                                        "jsonrpc": "2.0",
                                        "method": "eth_blockNumber",
                                        "params": [],
                                        "id": 1
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/JsonRpcResponse"
                                }
                            }
                        }
                    },
                    "400": {
                        "$ref": "#/components/responses/400"
                    },
                    "404": {
                        "$ref": "#/components/responses/404"
                    },
                    "500": {
                        "$ref": "#/components/responses/500"
                    }
                }
            }
        },
        "/chain/{chainId}/block/before/{timestamp}": {
            "get": {
                "description": "Get block before timestamp",
                "tags": ["blocks"],
                "parameters": [
                    {
                        "$ref": "#/components/parameters/ChainId"
                    },
                    {
                        "$ref": "#/components/parameters/Timestamp"
                    },
                    {
                        "$ref": "#/components/parameters/TimestampInclusive"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Block"
                                }
                            }
                        }
                    },
                    "400": {
                        "$ref": "#/components/responses/400"
                    },
                    "404": {
                        "$ref": "#/components/responses/404"
                    },
                    "500": {
                        "$ref": "#/components/responses/500"
                    }
                }
            }
        },
        "/chain/{chainId}/block/after/{timestamp}": {
            "get": {
                "description": "Get block after timestamp",
                "tags": ["blocks"],
                "parameters": [
                    {
                        "$ref": "#/components/parameters/ChainId"
                    },
                    {
                        "$ref": "#/components/parameters/Timestamp"
                    },
                    {
                        "$ref": "#/components/parameters/TimestampInclusive"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Block"
                                }
                            }
                        }
                    },
                    "400": {
                        "$ref": "#/components/responses/400"
                    },
                    "404": {
                        "$ref": "#/components/responses/404"
                    },
                    "500": {
                        "$ref": "#/components/responses/500"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Chain": {
                "description": "Chain information",
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "chainId": {
                        "type": "integer"
                    }
                }
            },
            "Block": {
                "description": "Block information",
                "type": "object",
                "properties": {
                    "number": {
                        "type": "number"
                    },
                    "timestamp": {
                        "type": "number"
                    },
                    "hash": {
                        "type": "string"
                    },
                    "parentHash": {
                        "type": "string",
                        "nullable": true
                    }
                }
            },
            "Error": {
                "description": "Error information",
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string"
                    }
                }
            },
            "JsonRpcHeaders": {
                "type": "object",
                "properties": {
                    "jsonrpc": {
                        "type": "string",
                        "default": "2.0",
                        "nullable": false
                    },
                    "id": {
                        "type": "integer"
                    }
                }
            },
            "JsonRpcError": {
                "type": "object",
                "nullable": true,
                "properties": {
                    "code": {
                        "type": "integer"
                    },
                    "message": {
                        "type": "string"
                    },
                    "data": {
                        "nullable": true
                    }
                }
            },
            "JsonRpcRequest": {
                "description": "JSON RPC Request",
                "allOf": [
                    {
                        "$ref": "#/components/schemas/JsonRpcHeaders"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "method": {
                                "type": "string",
                                "description": "EVM method name"
                            },
                            "params": {
                                "type": "array"
                            }
                        }
                    }
                ]
            },
            "JsonRpcResponse": {
                "description": "JSON RPC Success response",
                "allOf": [
                    {
                        "$ref": "#/components/schemas/JsonRpcHeaders"
                    },
                    {
                        "oneOf": [
                            {
                                "type": "object",
                                "properties": {
                                    "result": {
                                        "type": "string"
                                    }
                                }
                            },
                            {
                                "type": "object",
                                "properties": {
                                    "error": {
                                        "$ref": "#/components/schemas/JsonRpcError"
                                    }
                                }
                            }
                        ]
                    }
                ]
            }
        },
        "parameters": {
            "ChainId": {
                "name": "chainId",
                "in": "path",
                "required": true,
                "description": "Native EVM chain ID",
                "schema": {
                    "type": "integer"
                }
            },
            "Timestamp": {
                "name": "timestamp",
                "in": "path",
                "required": true,
                "description": "UNIX Timestamp",
                "schema": {
                    "type": "integer"
                }
            },
            "TimestampInclusive": {
                "name": "inclusive",
                "in": "query",
                "required": false,
                "schema": {
                    "type": "boolean"
                }
            }
        },
        "responses": {
            "400": {
                "description": "Bad request",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            },
            "404": {
                "description": "Not found",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            },
            "500": {
                "description": "Internal server error",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            }
        }
    }
}
