Hedera Agent Kit - CoinCap Plugin

April 24, 2026 ยท View on GitHub

A plugin for Hedera Agent Kit JS that provides integration with the CoinCap API

In this plugin we use CoinCap to get the current price in USD of one HBAR and combine it with the power of the Hedera Agent Kit to get your current balance of HBAR in USD currency.

Overview

This plugin enables AI agents to interact with the CoinCap API

Installation in the example index.js agent

1.- Install the plugin

npm install coincap-hedera-plugin

2.- Add your CoinCap API Bearer token in the .env file ( You get it in the CoinCap website )

# Coincap API needed by coincap-hedera-plugin
COINCAP_BEARER_TOKEN=******************************

3.- Import the plugin code in your index.js (Hedera Agent)

// CoinCap plugin to connect to CoinCap API
import { CoinCapHederaPlugin } from 'coincap-hedera-plugin';

If you want to restrict the agent to a specific tool from this plugin, import the tool-name map as well:

import { CoinCapHederaPlugin, coinCapHederaPluginToolNames } from 'coincap-hedera-plugin';

const { GET_HBAR_PRICE_IN_USD_TOOL } = coinCapHederaPluginToolNames;

4.- Import the coreAccountQueryPlugin plugin code in your index.js (Hedera Agent)

This core plugin is already provided by the Hedera, it is needed to query the account (read its balance)

import { coreAccountQueryPlugin } from 'hedera-agent-kit';

5.- Add the query and account plugins from core Hedera Agent code, and, this new plugin, in the plugins section of the agent

const hederaAgentToolkit = new HederaLangchainToolkit({
client,
configuration: {
    tools: [],
    plugins: [coreAccountQueryPlugin, CoinCapHederaPlugin], // <---- Add the plugin here

6.- Use a prompt to ask for you current balance and tell the agent to want it in USD currency, for example like this:

const response = await agent.invoke(
{ messages: [{ role: 'user', content: "Get my balance in HBAR and give it to me converted to USD currency" }] },
{ configurable: { thread_id: '1' } }
);

Note

The previous prompt results in a multi-step tool invocation:

  • Fetch the HBAR balance.
  • Fetch the current HBAR price.
  • Convert the balance to USD.

It is important for developers to be aware of, as configurations that limit the agent to only one tool call per request will cause this prompt to fail or behave incorrectly.

7.- Now you can run the example agent and you should get your current HBAR balance converted to USD currency

node index.js

Tools

Get HBAR price in USD

Invoke the CoinCap API to get the current price in USD of one HBAR

JS Function

function getHBARPriceInUSD()

Input Parameters

None

Output Values

ValueTypeDescription
ResultNumberValue in USD currency of 1 HBAR according to CoinCap

Example Prompt

Get my balance in HBAR and give it to me converted to USD currency

TypeScript support

Type declarations are shipped with the package (plugin.d.ts), so no additional setup is required in TypeScript projects.

Optional: Plugin distribution, only needed to publish the npm package

npm login
npm publish