UNPKG

rsshub

Version:
53 lines (52 loc) 1.87 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as config } from "./config-BfTrYkQS.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.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 limit = Number(ctx.req.query("limit") ?? 20); const response = await rofetch("https://api.etherscan.io/v2/api", { query: { chainid: 1, module: "account", action: "txlist", address, page: 1, offset: limit, 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 };