1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { alchemyFetch } from "https://esm.town/v/jamiedubs/alchemyClient";
export async function getBalances(address: string) {
const [tokens, eth] = await Promise.all([
alchemyFetch(`getTokenBalances?address=${address}`),
alchemyFetch(`getBalance?address=${address}`),
]);
return { tokens, eth };
}
export default async function ethereumTokenBalances(req: Request): Promise<Response> {
const searchParams = new URL(req.url).searchParams;
const address = searchParams.get("address");
const format = searchParams.get("format")?.toLowerCase() ?? "text";
if (!address) {
return Response.json({ error: "you must specify ?address" });
}
const json = await getBalances(address);
return Response.json(json);
}