Skip to content

Commit 8a6c9f0

Browse files
add blocks by timestamp
1 parent 5f44eb3 commit 8a6c9f0

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed

blocks/blocks.yaml

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
openapi: 3.1.0
2+
info:
3+
title: ⛓️ Block Timestamp API
4+
version: "1.0"
5+
servers:
6+
- url: https://api.g.alchemy.com/data/v1
7+
# x-sandbox:
8+
# category:
9+
# type:
10+
# $ref: '../components/sandbox.yaml#/Category'
11+
# value: blocks
12+
paths:
13+
"/{apiKey}/utility/blocks/by-timestamp":
14+
get:
15+
summary: Blocks by Timestamp
16+
description: Fetches the first block before or after a given timestamp. Returns the block's number and on-chain timestamp.
17+
tags: ["Blocks API Endpoints"]
18+
x-readme:
19+
samples-languages:
20+
- javascript
21+
- curl
22+
- python
23+
- go
24+
parameters:
25+
- $ref: '#/components/schemas/apiKey'
26+
- $ref: '#/components/schemas/networks'
27+
- $ref: '#/components/schemas/timestamp'
28+
- $ref: '#/components/schemas/direction'
29+
responses:
30+
"200":
31+
description: Successful response
32+
content:
33+
application/json:
34+
schema:
35+
$ref: "#/components/schemas/BlockTimestampResponse"
36+
"400":
37+
description: 'Bad Request: Malformed request or missing parameters.'
38+
content:
39+
application/json:
40+
schema:
41+
$ref: "#/components/schemas/ErrorResponse"
42+
"429":
43+
description: 'Too Many Requests: Rate limit exceeded.'
44+
content:
45+
application/json:
46+
schema:
47+
$ref: "#/components/schemas/ErrorResponse"
48+
operationId: blocks-by-timestamp
49+
components:
50+
securitySchemes:
51+
apiKey:
52+
type: apiKey
53+
name: Authorization
54+
in: header
55+
description: An API key that will be supplied in a named header.
56+
x-default: Bearer API_KEY
57+
schemas:
58+
apiKey:
59+
name: apiKey
60+
in: path
61+
schema:
62+
type: string
63+
default: docs-demo
64+
description: |
65+
<style>
66+
.custom-style {
67+
color: #048FF4;
68+
}
69+
</style>
70+
For higher throughput, <span class="custom-style"><a href="https://alchemy.com/?a=docs-demo" target="_blank">create your own API key</a></span>
71+
required: true
72+
networks:
73+
name: networks
74+
description: |
75+
<style>
76+
.custom-style {
77+
color: #048FF4;
78+
}
79+
</style>
80+
Array of networks to query on. The response will be an array with one block per network. Find network enums <span class="custom-style"><a href="https://dashboard.alchemy.com/chains" target="_blank">here</a></span>
81+
schema:
82+
type: array
83+
minItems: 1
84+
maxItems: 3
85+
items:
86+
type: string
87+
default: eth-mainnet
88+
in: query
89+
required: true
90+
timestamp:
91+
name: timestamp
92+
description: Unix or ISO timestamp
93+
schema:
94+
type: string
95+
default: 2025-02-28T19:38:57Z
96+
required: true
97+
in: query
98+
direction:
99+
name: direction
100+
required: true
101+
description: Return the first block "BEFORE" or "AFTER" the provided timestamp
102+
schema:
103+
type: string
104+
enum:
105+
- BEFORE
106+
- AFTER
107+
default: AFTER
108+
in: query
109+
ErrorResponse:
110+
type: object
111+
properties:
112+
error:
113+
type: object
114+
properties:
115+
message:
116+
type: string
117+
description: Detailed error message.
118+
required:
119+
- message
120+
description: Error details.
121+
required:
122+
- error
123+
# BlockTimestampResponse:
124+
# type: object
125+
# properties:
126+
# data:
127+
# type: array
128+
# description: List of blocks
129+
# items:
130+
# network:
131+
# type: string
132+
# description: Network the block corresponds to
133+
# required: true
134+
# blockData:
135+
# type: object
136+
# properties:
137+
# number:
138+
# type: int
139+
# description: Block number
140+
# timestamp:
141+
# type: string
142+
# description: ISO timestamp of the block
143+
# required:
144+
# - number
145+
# - timestamp
146+
# required:
147+
# - data
148+
149+
BlockTimestampResponse:
150+
type: object
151+
properties:
152+
data:
153+
type: array
154+
description: List of blocks
155+
items:
156+
$ref: "#/components/schemas/BlockTimestampResponseItem"
157+
required:
158+
- data
159+
160+
BlockTimestampResponseItem:
161+
type: object
162+
properties:
163+
network:
164+
type: string
165+
description: Network identifier
166+
block:
167+
type: object
168+
properties:
169+
number:
170+
type: integer
171+
description: Block number
172+
timestamp:
173+
type: string
174+
description: ISO timestamp of the block
175+
required:
176+
- number
177+
- timestamp
178+
required:
179+
- network
180+
- block

0 commit comments

Comments
 (0)