UNPKG

@agentek/tools

Version:

Blockchain tools for AI agents

65 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBtcAddressInfo = exports.getBtcTxDetails = exports.getBlockTxids = exports.getLatestBtcBlock = void 0; const client_js_1 = require("../client.js"); const zod_1 = require("zod"); const BASE_URL = "https://blockstream.info/api"; exports.getLatestBtcBlock = (0, client_js_1.createTool)({ name: "getLatestBtcBlock", description: "Fetches the latest Bitcoin block details.", parameters: zod_1.z.object({}), execute: async () => { const latestHashRes = await fetch(`${BASE_URL}/blocks`); if (!latestHashRes.ok) { throw new Error("Failed to fetch latest blocks."); } const blocks = await latestHashRes.json(); return blocks[0]; }, }); exports.getBlockTxids = (0, client_js_1.createTool)({ name: "getBtcBlockTxids", description: "Returns a list of transaction IDs in a block, given the block hash.", parameters: zod_1.z.object({ blockHash: zod_1.z.string().describe("Block hash to fetch txids from"), }), execute: async (_client, args) => { const res = await fetch(`https://blockstream.info/api/block/${args.blockHash}/txids`); if (!res.ok) { throw new Error("Failed to fetch txids from block."); } const txids = await res.json(); return { txids }; }, }); exports.getBtcTxDetails = (0, client_js_1.createTool)({ name: "getBtcTxDetails", description: "Fetches details for a given Bitcoin transaction ID (txid).", parameters: zod_1.z.object({ txid: zod_1.z.string().describe("Transaction ID to fetch details for."), }), execute: async (_client, args) => { const { txid } = args; const res = await fetch(`${BASE_URL}/tx/${txid}`); if (!res.ok) { throw new Error("Failed to fetch transaction details."); } return await res.json(); }, }); exports.getBtcAddressInfo = (0, client_js_1.createTool)({ name: "getBtcAddressInfo", description: "Fetches information about a Bitcoin address including balance and tx count.", parameters: zod_1.z.object({ address: zod_1.z.string().describe("Bitcoin address to lookup."), }), execute: async (_client, args) => { const { address } = args; const res = await fetch(`${BASE_URL}/address/${address}`); if (!res.ok) { throw new Error("Failed to fetch address info."); } return await res.json(); }, }); //# sourceMappingURL=tools.js.map