UNPKG

rsshub

Version:
52 lines (51 loc) 1.84 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as config } from "./config-Bpyy15zS.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as ConfigNotFoundError } from "./config-not-found-fQ5mxvDU.mjs"; //#region lib/routes/etherscan/transactions.ts const route = { path: "/transactions/:address", categories: ["finance"], example: "/etherscan/transactions/0x283af0b28c62c092c9727f1ee09c02ca627eb7f5", parameters: { address: "地址" }, features: { requireConfig: [{ name: "ETHERSCAN_API_KEY", description: "Etherscan API key, can be obtained from https://etherscan.io/myapikey" }] }, name: "转账追踪", maintainers: ["Pretty9"], handler }; async function handler(ctx) { if (!config.etherscan.apiKey) throw new ConfigNotFoundError("Etherscan RSS is disabled due to the lack of ETHERSCAN_API_KEY"); const { address } = ctx.req.param(); const response = await rofetch("https://api.etherscan.io/v2/api", { query: { chainid: 1, module: "account", action: "txlist", address, page: 1, offset: Number(ctx.req.query("limit") ?? 20), sort: "desc", apikey: config.etherscan.apiKey } }); if (response.status !== "1") throw new Error(Array.isArray(response.result) ? response.message : response.result); return { title: "etherscan transactions", link: "https://etherscan.io/", language: "en", description: "ethereum address transactions", item: response.result.map((item) => { const value = (Number(item.value) / 10 ** 18).toFixed(8); return { title: `TransactionHash: ${item.hash}`, description: `From: ${item.from} <br> To: ${item.to} <br> Value: ${value} <br> Block: ${item.blockNumber}`, link: `https://etherscan.io/tx/${item.hash}`, pubDate: parseDate(item.timeStamp, "X"), guid: item.hash }; }) }; } //#endregion export { route };