Fetch Onchain Data Using Agent Lib
The Senpi Agent Lib is a utility library that contains several reusable functions that can be used to fetch onchain data from your AI Agent Skills.
Importing the Senpi Agent Lib
To import the Senpi Agent Lib, you simply import it in your Skill's action file as shown below:
import * as agentLib from "@moxie-protocol/moxie-agent-lib";
From here, you can use all the functions available in agentLib
to fetch the onchain data you need.
Fetching Onchain Data
For example, you want to fetch the token metadata for a given token address. In this case, you can use the getTokenMetadata
function in your Skill's action handler
code as shown below:
import {
type Action,
type IAgentRuntime,
type Memory,
type HandlerCallback,
type State,
} from "@moxie-protocol/core";
import { getTokenMetadata } from "@moxie-protocol/moxie-agent-lib";
export const exampleAction: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State,
_options: { [key: string]: unknown },
callback: HandlerCallback
) => {
// Get Token Metadata using Senpi Agent Lib
const tokenMetadata = await getTokenMetadata(tokenAddress, runtime);
return true;
},
};
To learn all the functions available in the Senpi Agent Lib, please refer to the Senpi Agent Lib References.
Developer Support
If you have any questions or need help with other use cases, feel free to join the Senpi Telegram Developers Channel and ask your questions there.
Our team is always ready to help you with any questions you may have.