pharos-agent-kit
Version:
Connect AI Agents to Pharos protocols
45 lines (44 loc) • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PharosERC20TransferTool = void 0;
const tools_1 = require("langchain/tools");
const zod_1 = require("zod");
const PharosERC20TransferInputSchema = zod_1.z.object({
amount: zod_1.z.string().min(1, "Amount must not be empty"),
recipient: zod_1.z.string(),
tokenAddress: zod_1.z.string().optional(),
});
class PharosERC20TransferTool extends tools_1.StructuredTool {
constructor(pharosKit) {
super();
this.pharosKit = pharosKit;
this.name = "pharos_erc20_transfer";
this.description = `Transfer ETH or ERC20 tokens to another wallet.
Parameters:
- amount: The amount of tokens to transfer as a string (e.g., "1.5") (required).
- recipient: The recipient's wallet address (required).
- tokenAddress: Optional ERC20 token address. If not provided, transfers ETH`;
this.schema = PharosERC20TransferInputSchema;
}
async _call(input) {
try {
const transfer = await this.pharosKit.transfer(input.recipient, parseFloat(input.amount), input.tokenAddress);
if (!transfer) {
throw new Error("Transfer failed");
}
return JSON.stringify({
status: "success",
hash: transfer,
});
}
catch (error) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
exports.PharosERC20TransferTool = PharosERC20TransferTool;
//# sourceMappingURL=transfer.js.map