AI prompts
base on PumpDotFun SDK # PumpFunSDK README
## Important
Never click links in this repository leaving github, never click links in Issues, don't run code that others post without reading it, this software is provided "as is," without warranty.
## Overview
The `PumpDotFunSDK` is designed to interact with the Pump.fun decentralized application. It provides methods for creating, buying, and selling tokens using the Solana blockchain. The SDK handles the necessary transactions and interactions with the Pump.fun program.
## Installation
`
npm i pumpdotfun-sdk
`
## Usage Example
First you need to create a `.env` file and set your RPC URL like in the `.env.example`
Then you need to fund an account with atleast 0.004 SOL that is generated when running the command below
`
npx ts-node example/basic/index.ts
`
```typescript
import dotenv from "dotenv";
import { Connection, Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
import { DEFAULT_DECIMALS, PumpFunSDK } from "pumpdotfun-sdk";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { AnchorProvider } from "@coral-xyz/anchor";
import {
getOrCreateKeypair,
getSPLBalance,
printSOLBalance,
printSPLBalance,
} from "./util";
dotenv.config();
const KEYS_FOLDER = __dirname + "/.keys";
const SLIPPAGE_BASIS_POINTS = 100n;
const getProvider = () => {
if (!process.env.HELIUS_RPC_URL) {
throw new Error("Please set HELIUS_RPC_URL in .env file");
}
const connection = new Connection(process.env.HELIUS_RPC_URL || "");
const wallet = new NodeWallet(new Keypair());
return new AnchorProvider(connection, wallet, { commitment: "finalized" });
};
const createAndBuyToken = async (sdk, testAccount, mint) => {
const tokenMetadata = {
name: "TST-7",
symbol: "TST-7",
description: "TST-7: This is a test token",
filePath: "example/basic/random.png",
};
const createResults = await sdk.createAndBuy(
testAccount,
mint,
tokenMetadata,
BigInt(0.0001 * LAMPORTS_PER_SOL),
SLIPPAGE_BASIS_POINTS,
{
unitLimit: 250000,
unitPrice: 250000,
}
);
if (createResults.success) {
console.log("Success:", `https://pump.fun/${mint.publicKey.toBase58()}`);
printSPLBalance(sdk.connection, mint.publicKey, testAccount.publicKey);
} else {
console.log("Create and Buy failed");
}
};
const buyTokens = async (sdk, testAccount, mint) => {
const buyResults = await sdk.buy(
testAccount,
mint.publicKey,
BigInt(0.0001 * LAMPORTS_PER_SOL),
SLIPPAGE_BASIS_POINTS,
{
unitLimit: 250000,
unitPrice: 250000,
}
);
if (buyResults.success) {
printSPLBalance(sdk.connection, mint.publicKey, testAccount.publicKey);
console.log("Bonding curve after buy", await sdk.getBondingCurveAccount(mint.publicKey));
} else {
console.log("Buy failed");
}
};
const sellTokens = async (sdk, testAccount, mint) => {
const currentSPLBalance = await getSPLBalance(
sdk.connection,
mint.publicKey,
testAccount.publicKey
);
console.log("currentSPLBalance", currentSPLBalance);
if (currentSPLBalance) {
const sellResults = await sdk.sell(
testAccount,
mint.publicKey,
BigInt(currentSPLBalance * Math.pow(10, DEFAULT_DECIMALS)),
SLIPPAGE_BASIS_POINTS,
{
unitLimit: 250000,
unitPrice: 250000,
}
);
if (sellResults.success) {
await printSOLBalance(sdk.connection, testAccount.publicKey, "Test Account keypair");
printSPLBalance(sdk.connection, mint.publicKey, testAccount.publicKey, "After SPL sell all");
console.log("Bonding curve after sell", await sdk.getBondingCurveAccount(mint.publicKey));
} else {
console.log("Sell failed");
}
}
};
const main = async () => {
try {
const provider = getProvider();
const sdk = new PumpFunSDK(provider);
const connection = provider.connection;
const testAccount = getOrCreateKeypair(KEYS_FOLDER, "test-account");
const mint = getOrCreateKeypair(KEYS_FOLDER, "mint");
await printSOLBalance(connection, testAccount.publicKey, "Test Account keypair");
const globalAccount = await sdk.getGlobalAccount();
console.log(globalAccount);
const currentSolBalance = await connection.getBalance(testAccount.publicKey);
if (currentSolBalance === 0) {
console.log("Please send some SOL to the test-account:", testAccount.publicKey.toBase58());
return;
}
console.log(await sdk.getGlobalAccount());
let bondingCurveAccount = await sdk.getBondingCurveAccount(mint.publicKey);
if (!bondingCurveAccount) {
await createAndBuyToken(sdk, testAccount, mint);
bondingCurveAccount = await sdk.getBondingCurveAccount(mint.publicKey);
}
if (bondingCurveAccount) {
await buyTokens(sdk, testAccount, mint);
await sellTokens(sdk, testAccount, mint);
}
} catch (error) {
console.error("An error occurred:", error);
}
};
main();
```
### PumpDotFunSDK Class
The `PumpDotFunSDK` class provides methods to interact with the PumpFun protocol. Below are the method signatures and their descriptions.
#### createAndBuy
```typescript
async createAndBuy(
creator: Keypair,
mint: Keypair,
createTokenMetadata: CreateTokenMetadata,
buyAmountSol: bigint,
slippageBasisPoints: bigint = 500n,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
```
- Creates a new token and buys it.
- **Parameters**:
- `creator`: The keypair of the token creator.
- `mint`: The keypair of the mint account.
- `createTokenMetadata`: Metadata for the token.
- `buyAmountSol`: Amount of SOL to buy.
- `slippageBasisPoints`: Slippage in basis points (default: 500).
- `priorityFees`: Priority fees (optional).
- `commitment`: Commitment level (default: DEFAULT_COMMITMENT).
- `finality`: Finality level (default: DEFAULT_FINALITY).
- **Returns**: A promise that resolves to a `TransactionResult`.
#### buy
```typescript
async buy(
buyer: Keypair,
mint: PublicKey,
buyAmountSol: bigint,
slippageBasisPoints: bigint = 500n,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
```
- Buys a specified amount of tokens.
- **Parameters**:
- `buyer`: The keypair of the buyer.
- `mint`: The public key of the mint account.
- `buyAmountSol`: Amount of SOL to buy.
- `slippageBasisPoints`: Slippage in basis points (default: 500).
- `priorityFees`: Priority fees (optional).
- `commitment`: Commitment level (default: DEFAULT_COMMITMENT).
- `finality`: Finality level (default: DEFAULT_FINALITY).
- **Returns**: A promise that resolves to a `TransactionResult`.
#### sell
```typescript
async sell(
seller: Keypair,
mint: PublicKey,
sellTokenAmount: bigint,
slippageBasisPoints: bigint = 500n,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
```
- Sells a specified amount of tokens.
- **Parameters**:
- `seller`: The keypair of the seller.
- `mint`: The public key of the mint account.
- `sellTokenAmount`: Amount of tokens to sell.
- `slippageBasisPoints`: Slippage in basis points (default: 500).
- `priorityFees`: Priority fees (optional).
- `commitment`: Commitment level (default: DEFAULT_COMMITMENT).
- `finality`: Finality level (default: DEFAULT_FINALITY).
- **Returns**: A promise that resolves to a `TransactionResult`.
#### addEventListener
```typescript
addEventListener<T extends PumpFunEventType>(
eventType: T,
callback: (event: PumpFunEventHandlers[T], slot: number, signature: string) => void
): number
```
- Adds an event listener for the specified event type.
- **Parameters**:
- `eventType`: The type of event to listen for.
- `callback`: The callback function to execute when the event occurs.
- **Returns**: An identifier for the event listener.
#### removeEventListener
```typescript
removeEventListener(eventId: number): void
```
- Removes the event listener with the specified identifier.
- **Parameters**:
- `eventId`: The identifier of the event listener to remove.
### Running the Examples
#### Basic Example
To run the basic example for creating, buying, and selling tokens, use the following command:
```bash
npx ts-node example/basic/index.ts
```
#### Event Subscription Example
This example demonstrates how to set up event subscriptions using the PumpFun SDK.
#### Script: `example/events/events.ts`
```typescript
import dotenv from "dotenv";
import { Connection, Keypair } from "@solana/web3.js";
import { PumpFunSDK } from "pumpdotfun-sdk";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { AnchorProvider } from "@coral-xyz/anchor";
dotenv.config();
const getProvider = () => {
if (!process.env.HELIUS_RPC_URL) {
throw new Error("Please set HELIUS_RPC_URL in .env file");
}
const connection = new Connection(process.env.HELIUS_RPC_URL || "");
const wallet = new NodeWallet(new Keypair());
return new AnchorProvider(connection, wallet, { commitment: "finalized" });
};
const setupEventListeners = async (sdk) => {
const createEventId = sdk.addEventListener("createEvent", (event, slot, signature) => {
console.log("createEvent", event, slot, signature);
});
console.log("Subscribed to createEvent with ID:", createEventId);
const tradeEventId = sdk.addEventListener("tradeEvent", (event, slot, signature) => {
console.log("tradeEvent", event, slot, signature);
});
console.log("Subscribed to tradeEvent with ID:", tradeEventId);
const completeEventId = sdk.addEventListener("completeEvent", (event, slot, signature) => {
console.log("completeEvent", event, slot, signature);
});
console.log("Subscribed to completeEvent with ID:", completeEventId);
};
const main = async () => {
try {
const provider = getProvider();
const sdk = new PumpFunSDK(provider);
// Set up event listeners
await setupEventListeners(sdk);
} catch (error) {
console.error("An error occurred:", error);
}
};
main();
```
#### Running the Event Subscription Example
To run the event subscription example, use the following command:
```bash
npx ts-node example/events/events.ts
```
## Contributing
We welcome contributions! Please submit a pull request or open an issue to discuss any changes.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Here is a sample "Use at Your Own Risk" disclaimer for a GitHub repository:
---
## Disclaimer
This software is provided "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
**Use at your own risk.** The authors take no responsibility for any harm or damage caused by the use of this software. Users are responsible for ensuring the suitability and safety of this software for their specific use cases.
By using this software, you acknowledge that you have read, understood, and agree to this disclaimer.
---
Feel free to customize it further to suit the specific context and requirements of your project.
---
By following this README, you should be able to install the PumpDotFun SDK, run the provided examples, and understand how to set up event listeners and perform token operations.
", Assign "at most 3 tags" to the expected json: {"id":"12240","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"