In this guide, we’ll walk you through connecting to the Trade Pump Fun API using Node.js. The goal is to create a simple script that pings the API to verify the connection.
Before starting, ensure you have the following installed:
- Node.js (You can check if it's installed by running node -v in your terminal)
- npm (Node package manager, usually installed with Node.js)
You also need a valid API key for the Trade Pump Fun API. If you don't have one, you can create a free account and receive one from Trade Pump Fun portal. Navigate to https://tradepump.fun/sign-up, after sign up go to "API Keys" in the left navigation, and follow "Create API Key".
Start by creating a new directory for your project, installing/initializing typescript. Open a terminal and run the following:
Terminal
1
2
3
4
5
mkdir trade-pump-fun-api
cd trade-pump-fun-api
npm init -y
npm install --save-dev typescript
npx tsc --init
This will initialize a new Node.js project and generate a package.json file.
Update your package.json to the following ensuring you have all the correct dependencies
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"name": "1-connect-to-api",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"start": "ts-node src/index.ts"
},
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
},
"dependencies": {
"dotenv": "^16.4.7",
"tradepumpfun": "latest"
}
}
Run npm install to install the packages from your package.json
Terminal
1
npm install
Create a src
folder inside your project, and add a single file index.ts
within your src folder. This is where we will write the code connecting to the API.
First we wish to initialize the PumpApiClient
from the tradepumpfun
npm package.
index.ts
1
2
3
4
5
6
7
8
9
10
11
import dotenv from 'dotenv';
import { PumpApiClient } from 'tradepumpfun';
dotenv.config();
// Safer to .env file with API_KEY=<your-api-key>
const apiKey = process.env.API_KEY || '<your-api-key>';
const client = new PumpApiClient({
apiKey,
});
The code above is doing two primary things, first it is receiving your API_Key, this key can be placed in a .env file within your project or directly in the code itself where <your-api-key>
is. Your API Key is private, you do not want to commit it to a public github repo.
To validate our connection to the Trade Pump Fun API we are going to use the ping
api endpoint which validates that we are connecting to the API, and that our API Key is valid.
index.ts
1
2
3
4
5
client.ping().then(ping => {
console.log(ping);
}).catch(error => {
console.error('Error pinging API:', error);
});
The code above is using your PumpApiClient
with your api key to ping the API server.
The full code all together in your index.ts
would be the following:
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import dotenv from 'dotenv';
import { PumpApiClient } from 'tradepumpfun';
dotenv.config();
// Safer to .env file with API_KEY=<your-api-key>
const apiKey = process.env.API_KEY || '<your-api-key>';
const client = new PumpApiClient({
apiKey,
});
client.ping().then(ping => {
console.log(ping);
}).catch(error => {
console.error('Error pinging API:', error);
});
To run the code we run npm run start
. If successful you will receive the following response:
Response
1
{ result: { access: 'granted' } }
If your request does not succeed check the error response, and validate that your API Key is valid.
You have now validated your connection to the tradepump.fun API and can start building your own trade bot.