Moxie Lib
Moxie Libs provides a suite of functions that enables developers to execute on-chain transactions and retrieve Moxie-related data efficiently.
With MoxieWalletClient
class, developers can send transactions, sign messages, and handle EIP-712 structured data.
The library also offers multiple functions to fetch Moxie users information by wallet addresses or Moxie User IDs, retrieve social profiles, and access Moxie creator coin portfolios.
These features make Moxie Libs an essential toolkit for building AI Agent Skills for the Moxie Skills Marketplace.
Pre-requisites
To enable the full functionality of Moxie Libs, you need to provide several environment variables to your existing .env
file:
PRIVATE_KEY= # Private key for executing tx with Moxie Lib, simulating agent wallet
AIRSTACK_API_KEY= # For fetching user's Moxie portfolio data
MOXIE_LIB_RPC_URL= # RPC URL for executing tx with Moxie Lib
Keep in mind that:
- For local development, every onchain transaction executed will be using the wallet that you provide from the
PRIVATE_KEY
, which will simulate the agent wallet on production - Since transactions are executed with the agent wallet, you need to make sure that the agent wallet has enough funds to cover the gas fees for the transaction
- The
MOXIE_LIB_RPC_URL
is the RPC URL only for local development purpose for executing tx with Moxie Lib that is chain specific. For transaction to be successful, you need to make sure that the chain ID you specify in the transaction is supported by the RPC URL
Send Transaction
Send or write an onchain transaction with an agent wallet.
For local development, the transaction will be executed from the wallet that you provide from the PRIVATE_KEY
to simulate the agent wallet on production.
import { MoxieWalletClient } from "@moxie-protocol/moxie-lib";
const wallet: MoxieWalletClient = state.agentWallet;
const { hash } = await wallet.sendTransaction("8543", {
toAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
value: 1e18,
});
Sign Message
Sign a message with the agent wallet.
import { MoxieWalletClient } from "@moxie-protocol/moxie-lib";
const wallet: MoxieWalletClient = state.agentWallet;
const { signature, encoding } = await wallet.signMessage("Hello Moxie!");
Sign Typed Data
Sign data that is structured in a way that is compatible with EIP-712.
import { MoxieWalletClient } from "@moxie-protocol/moxie-lib";
const wallet: MoxieWalletClient = state.agentWallet;
const { signature, encoding } = await wallet.signTypedData({
types: {
type: "object",
properties: {
EIP712Domain: { type: "array" },
},
additionalProperties: {
type: "array",
items: {
type: "object",
properties: {
name: { type: "string" },
type: { type: "string" },
},
required: ["name", "type"],
},
},
required: ["EIP712Domain"],
},
primaryType: { type: "string" },
domain: { type: "object" },
message: { type: "object" },
});
Fetch Moxie User Info By Wallet address
Fetch the Moxie User Info by providing the user's wallet address.
import { getUserMoxieWalletAddress } from "@moxie-protocol/moxie-lib";
const moxieUserInfo = await getUserMoxieWalletAddress(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
);
Fetch Moxie User Info By Moxie User ID
Fetch the Moxie User Info by providing the user's Moxie User ID.
import { getUserByMoxieId } from "@moxie-protocol/moxie-lib";
const moxieUserInfo = await getUserByMoxieId("M1");