@covalenthq/goldrush-mcp-server
Version:
GoldRush MCP Server for interacting with Covalent GoldRush API
150 lines • 6.53 kB
JavaScript
import { validQuoteValues } from "../utils/constants.js";
import { stringifyWithBigInt } from "../utils/helpers.js";
import { ChainName, } from "@covalenthq/client-sdk";
import { z } from "zod";
export function addTransactionServiceTools(server, goldRushClient) {
server.tool("transaction", "Commonly used to fetch and render a single transaction including its decoded log events.\n" +
"Required: chainName (blockchain network), txHash (transaction hash).\n" +
"Optional: quoteCurrency (currency to convert to, USD by default), " +
"noLogs (exclude event logs, true by default), " +
"withInternal (include internal transactions, false by default), " +
"withState (include state changes, false by default), " +
"withInputData (include input data, false by default).\n" +
"Tracing features (withInternal, withState, withInputData) supported on the following chains: eth-mainnet\n" +
"Returns comprehensive details about the specified transaction.", {
chainName: z.enum(Object.values(ChainName)),
txHash: z.string(),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional(),
noLogs: z.boolean().optional().default(true),
withInternal: z.boolean().optional(),
withState: z.boolean().optional(),
withInputData: z.boolean().optional(),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getTransaction(params.chainName, params.txHash, {
quoteCurrency: params.quoteCurrency,
noLogs: params.noLogs,
withInternal: params.withInternal,
withState: params.withState,
withInputData: params.withInputData,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (error) {
return {
content: [{ type: "text", text: `Error: ${error}` }],
isError: true,
};
}
});
server.tool("transaction_summary", "Commonly used to fetch the earliest and latest transactions, and the transaction count for a wallet.\n" +
"Required: chainName (blockchain network), walletAddress (wallet address).\n" +
"Optional: quoteCurrency, withGas (include gas usage statistics).\n" +
"Returns summary of transaction activity for the specified wallet.", {
chainName: z.enum(Object.values(ChainName)),
walletAddress: z.string(),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional(),
withGas: z.boolean().optional(),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getTransactionSummary(params.chainName, params.walletAddress, {
quoteCurrency: params.quoteCurrency,
withGas: params.withGas,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (err) {
return {
content: [{ type: "text", text: `Error: ${err}` }],
isError: true,
};
}
});
server.tool("transactions_for_address", "Commonly used to fetch and render the most recent transactions involving an address.\n" +
"Required: chainName (blockchain network), walletAddress (wallet address), page (page number).\n" +
"Optional: quoteCurrency, noLogs, blockSignedAtAsc (chronological order).\n" +
"Returns transactions for the specified page of results.", {
chainName: z.enum(Object.values(ChainName)),
walletAddress: z.string(),
page: z.number(),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional(),
noLogs: z.boolean().optional().default(true),
blockSignedAtAsc: z.boolean().optional(),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getPaginatedTransactionsForAddress(params.chainName, params.walletAddress, params.page, {
quoteCurrency: params.quoteCurrency,
noLogs: params.noLogs,
blockSignedAtAsc: params.blockSignedAtAsc,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (err) {
return {
content: [{ type: "text", text: `Error: ${err}` }],
isError: true,
};
}
});
server.tool("transactions_for_block", "Commonly used to fetch all transactions including their decoded log events in a block and further flag interesting wallets or transactions.\n" +
"Required: chainName (blockchain network), blockHeight (block number or latest).\n" +
"Optional: quoteCurrency, noLogs (exclude event logs).\n" +
"Returns all transactions from the specified block.", {
chainName: z.enum(Object.values(ChainName)),
blockHeight: z.union([z.string(), z.number(), z.literal("latest")]),
page: z.number(),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional(),
noLogs: z.boolean().optional(),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getTransactionsForBlockByPage(params.chainName, params.blockHeight, params.page, {
quoteCurrency: params.quoteCurrency,
noLogs: params.noLogs,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (err) {
return {
content: [{ type: "text", text: `Error: ${err}` }],
isError: true,
};
}
});
}
//# sourceMappingURL=TransactionService.js.map