jamiedubs-ethereumtokenbalances.web.val.run
Readme

fetch token balances from an Ethereum wallet. uses Alchemy. don't abuse my API key or I'll turn this off

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 token = searchParams.get("token");
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);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 30, 2024