UNPKG

@gluneau/hive-mcp-server

Version:

An MCP server that enables AI assistants to interact with the Hive blockchain

95 lines 4.54 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.voteOnPost = voteOnPost; exports.sendToken = sendToken; // Transaction-related tools implementation const dhive_1 = require("@hiveio/dhive"); const client_1 = __importDefault(require("../config/client")); const config_1 = __importDefault(require("../config")); const error_1 = require("../utils/error"); const response_1 = require("../utils/response"); // Vote on a post function voteOnPost(params) { return __awaiter(this, void 0, void 0, function* () { try { // Get credentials from environment variables const username = config_1.default.hive.username; const privateKey = config_1.default.hive.postingKey; if (!username || !privateKey) { return (0, response_1.errorResponse)('Error: HIVE_USERNAME or HIVE_POSTING_KEY environment variables are not set'); } // Create the vote operation const vote = { voter: username, author: params.author, permlink: params.permlink, weight: params.weight, }; // Create the broadcast instance and broadcast the vote const result = yield client_1.default.broadcast.vote(vote, dhive_1.PrivateKey.fromString(privateKey)); return (0, response_1.successJson)({ success: true, transaction_id: result.id, transaction_url: `https://www.hiveblockexplorer.com/tx/${result.id}`, block_num: result.block_num, voter: username, author: params.author, permlink: params.permlink, weight: params.weight, }); } catch (error) { return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'vote_on_post')); } }); } // Send HIVE or HBD to another account function sendToken(params) { return __awaiter(this, void 0, void 0, function* () { try { // Get credentials from environment variables const username = config_1.default.hive.username; const activeKey = config_1.default.hive.activeKey; if (!username || !activeKey) { return (0, response_1.errorResponse)('Error: HIVE_USERNAME or HIVE_ACTIVE_KEY environment variables are not set. Note that transfers require an active key, not a posting key.'); } // Format the amount with 3 decimal places and append the currency const formattedAmount = `${params.amount.toFixed(3)} ${params.currency}`; // Create the transfer operation const transfer = { from: username, to: params.to, amount: formattedAmount, memo: params.memo || '', }; // Broadcast the transfer using active key (required for transfers) const result = yield client_1.default.broadcast.transfer(transfer, dhive_1.PrivateKey.fromString(activeKey)); return (0, response_1.successJson)({ success: true, transaction_id: result.id, transaction_url: `https://www.hiveblockexplorer.com/tx/${result.id}`, block_num: result.block_num, from: username, to: params.to, amount: formattedAmount, memo: params.memo || '(no memo)', }); } catch (error) { return (0, response_1.errorResponse)((0, error_1.handleError)(error, 'send_token')); } }); } //# sourceMappingURL=transaction.js.map