Getting Started

Let's start by setting up a basic AI agent using PingAI's Ping Agent Kit that can perform actions on the Solana blockchain and that we can chat with:

A modern IDE is recommended for this guide. We will use Cursor for this example which has integrated AI features and can help you with any errors you may encounter.

You will need to have node with version 23.x.x installed. Open an empty folder using vscode or cursor and run the following command in the terminal:

This guide requires Node.js version `23.x.x`. Install it using [nvm](https://github.com/nvm-sh/nvm):

Copy

node --version  # Check current version
nvm install 23  # Install Node.js 23 if needed
nvm use 23      # Switch to Node.js 23

Copy

pnpm install ping-agent-kit
pnpm add @langchain/core @langchain/openai @langchain/langgraph dotenv bs58

Your IDE should setup the package.json file for you. If not, this is how it should look like:

Copy

{
  "dependencies": {
    "@langchain/core": "^0.3.33",
    "@langchain/langgraph": "^0.2.41",
    "@langchain/openai": "^0.3.17",
    "bs58": "^6.0.0",
    "dotenv": "^16.4.7",
    "ping-agent-kit": "^1.4.3"
  }
}

Create a .env file in the root of the project and add the following:

Copy

Note that we encode the private key to base58 before we parse it into the Ping agent constructor in the script so you can just put the byte array [34,2,34...] here in the env file.

You can create a key using the following command:

Copy

And copy the contents into your .env file for SOLANA_PRIVATE_KEY.

The OPENAI_API_KEY is the key for the OpenAI API and you can find it in the OpenAI platform

The RPC url we just leave at devnet for now.

Create a new file called agent.ts with the following content:

Copy

You can run this script using the following command:

Copy

This will start a simple chat with the agent.

### Test basic functionality

You can now ask it to show you your solana balance and ask it to request some devnet sol:

Copy

If the devnet faucet is empty you can use the web faucet instead and paste in your solana address.

Next ask the agent:

Copy

After the collection is created, mint an NFT:

Copy

This will mint you an NFT with the name Train1 and an image of a train.

You can also use any different metadata for your NFT which you can upload using pinata or any other storage provider. You should end up with something like this devnet train nft

Where to go from here?

  • You can now for example import the private key into your browser extension wallet to see the NFT.

  • You can ask the agent to show you all your NFTs. You will notice you will get an error for this action. This is because the default action to request assets uses the Helius Asset api to request assets so for that you would need to add a Helius API key to your .env file and pass it into the agent. pass it into the agent.

Copy

Last updated