### Install Dependencies and Build Package (npm) Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.1_activeTab=dependencies Commands to install project dependencies and build the package using npm. These are standard commands for Node.js projects. ```bash # Install dependencies: npm install # Build the package: npm run build ``` -------------------------------- ### Add NPM Token to Vercel Environment Variables Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.1_activeTab=code Instructs how to add the NPM_TOKEN to the environment variables in Vercel for frontend projects. This enables Vercel builds to authenticate with npm and install private dependencies. ```text For Frontend Repos, just add NPM_TOKEN to env var in Vercel ``` -------------------------------- ### Get Creator Vault Balance Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.19.0-devnet_activeTab=code Retrieves the total accumulated creator fees for both Pump and PumpSwap programs for a given user. This is useful for monitoring earned fees. ```javascript const user = PublicKey.unique(); console.log((await sdk.getCreatorVaultBalanceBothPrograms(user)).toString()); ``` -------------------------------- ### Get and Collect Creator Fees with Pump SDK Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=code Retrieves the total accumulated creator fees for both Pump and PumpSwap programs for a given user and generates instructions to collect these fees. The balance is returned as a string. ```javascript const user = PublicKey.unique(); // Getting total accumulated creator fees for both Pump and PumpSwap programs console.log((await sdk.getCreatorVaultBalanceBothPrograms(user)).toString()); // Collecting creator fees instructions const instructions = await sdk.collectCoinCreatorFeeInstructions(user); ``` -------------------------------- ### Get Total Creator Fees Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.19.0-devnet_activeTab=dependencies Retrieves the total accumulated creator fees for both Pump and PumpSwap programs for a given user. This is useful for tracking revenue share. It returns the balance as a string. Requires @solana/web3.js. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); // Assuming 'sdk' is an initialized PumpSdk instance const user = PublicKey.unique(); console.log((await sdk.getCreatorVaultBalanceBothPrograms(user)).toString()); ``` -------------------------------- ### Create and Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23.0-devnet_activeTab=dependencies Generates instructions to both create a new coin and immediately buy it using SOL. This is useful for initial liquidity provisioning. It requires coin details, user information, and the amount of SOL to use for purchase. Dependencies include @solana/web3.js and bn.js. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); const { getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk/lib/utils"); // Assuming utility path // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Create and Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.21.0-devnet_activeTab=dependencies Generates Solana instructions to both create a new coin and immediately buy a portion of it using SOL. Requires fetching global state and calculating token amounts. Dependencies include PublicKey, BN.js, and PumpSdk. ```javascript const { PublicKey } = require('@solana/web3.js'); const { PumpSdk } = require('@pump-fun/pump-sdk'); const { BN } = require('bn.js'); // Assuming 'sdk' is an initialized PumpSdk instance and getBuyTokenAmountFromSolAmount is available const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Create and Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.17_activeTab=readme Creates instructions for both minting a new coin and immediately buying a portion of it in a single transaction. This is useful for launching new tokens efficiently. It requires details about the coin, user, and the amount of SOL to spend. ```javascript const { PublicKey, BN } = require("@solana/web3.js"); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk"); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Create and Buy Coin Instructions with Pump SDK Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=code Generates instructions to both create a new coin and immediately buy a portion of it using SOL. Requires coin details, user information, and the amount of SOL to spend. It fetches global state and calculates the token amount to buy. ```javascript const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Pump SDK Initialization Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.19.0-devnet_activeTab=dependents Demonstrates how to initialize the Pump SDK with a Solana connection. ```APIDOC ## Pump SDK Initialization ### Description Initializes the Pump SDK with a Solana connection object. ### Method Constructor ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const connection = new Connection( "https://api.devnet.solana.com", "confirmed", ); const sdk = new PumpSdk(connection); ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Create and Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.22.1-devnet_activeTab=versions Generates Solana instructions to both create a new coin and immediately buy a portion of it. This is useful for launching new tokens. It requires bonding curve information and the desired SOL amount for purchase. ```javascript const { PublicKey, BN } = require('@solana/web3.js'); const { getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=readme Generates instructions for buying a coin. Requires mint and user public keys, along with state information fetched using `fetchBuyState`. Specifies the amount of SOL to spend and slippage tolerance. ```javascript const { PublicKey, Connection } = require("@solana/web3.js"); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Create and Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23_activeTab=versions Generates instructions to both create a new coin and immediately buy it in the same transaction. This requires fetching global state and specifying the SOL amount for purchase. ```javascript const { PublicKey } = require('@solana/web3.js'); const { BN } = require('bn.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Create and Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.19.0-devnet_activeTab=dependencies Generates instructions to both create a new coin and immediately buy a portion of it in a single transaction. This is useful for launching new tokens. It requires fetching global state and calculating token amounts based on SOL input. Dependencies include @solana/web3.js and bn.js. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), // Helper function }); ``` -------------------------------- ### Create Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=readme Generates instructions for creating a new coin (mint). Requires mint, creator, and user public keys, along with coin metadata (name, symbol, URI). Optionally, can create and buy coins in the same transaction. ```javascript const { PublicKey, Connection } = require("@solana/web3.js"); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); // Creating coin instruction const instruction = await sdk.createInstruction({ mint, name: "name", symbol: "symbol", uri: "uri", creator, user, }); // Creating and buying coins in the same transaction const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.20.0-devnet_activeTab=readme Creates instructions for a user to buy a specified amount of a coin using SOL. Requires pre-fetched state, coin details, user, SOL amount, and slippage tolerance. ```javascript const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Create and Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.17 Generates instructions for both creating a new coin and immediately buying a portion of it with SOL. This is a convenience function for a common workflow. It requires details of the coin to be created and the amount of SOL to use for purchase. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), // Helper function needed }); ``` -------------------------------- ### Create Coin Instruction Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23_activeTab=dependents Generates instructions for creating a new coin (token) on the Solana blockchain. Requires mint, creator, and user public keys, along with coin metadata. ```javascript const { PublicKey, Connection } = require('@solana/web3.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); const BN = require('bn.js'); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const instruction = await sdk.createInstruction({ mint, name: "name", symbol: "symbol", uri: "uri", creator, user, }); ``` -------------------------------- ### Buy Coin Instructions with Pump SDK Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.19.0-devnet Generates instructions for buying a coin on the Pump platform. This requires fetching the current state of the bonding curve and user accounts. It takes parameters like mint, user, SOL amount, and slippage tolerance to calculate the number of tokens to buy. ```javascript const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Create Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.22_activeTab=dependents Generates instructions for creating a new coin (mint) on the Solana blockchain. It requires parameters like mint public key, creator, user, and metadata such as name, symbol, and URI. ```javascript const { PublicKey, Connection } = require('@solana/web3.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); const BN = require('bn.js'); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const instruction = await sdk.createInstruction({ mint, name: "name", symbol: "symbol", uri: "uri", creator, user, }); // Example for creating and buying in the same transaction const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23_activeTab=versions Creates instructions for buying a specified amount of a coin using SOL. It requires pre-fetched state information and calculates the token amount based on the SOL provided. ```javascript const { PublicKey } = require('@solana/web3.js'); const { BN } = require('bn.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); // Assuming 'sdk' is an initialized PumpSdk instance and state is fetched const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk_activeTab=dependents Creates instructions to buy a specified amount of a coin using SOL. It fetches necessary state information like global configuration, bonding curve details, and user account info. Requires slippage tolerance. ```javascript const { PublicKey, Connection } = require('@solana/web3.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); const BN = require('bn.js'); // Assuming 'sdk' is an initialized PumpSdk instance // const connection = new Connection("https://api.devnet.solana.com", "confirmed"); // const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Buy Coin Instructions with Pump SDK Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=code Generates instructions to buy a specified amount of a coin using SOL. Requires coin's mint address, user's public key, and the amount of SOL to spend. It fetches necessary state information like bonding curve and user accounts to calculate the transaction details. ```javascript const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.21.0-devnet_activeTab=dependencies Creates Solana instructions to purchase a specified amount of a coin using SOL, considering slippage. Requires pre-fetched state information like bonding curve details and user accounts. Dependencies include PublicKey, BN.js, and PumpSdk. ```javascript const { PublicKey } = require('@solana/web3.js'); const { PumpSdk } = require('@pump-fun/pump-sdk'); const { BN } = require('bn.js'); // Assuming 'sdk' is an initialized PumpSdk instance, getBuyTokenAmountFromSolAmount is available, // and state variables like global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo are fetched. const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.17_activeTab=dependents Creates instructions to buy a specified amount of a coin using SOL. It requires fetching the current state of the bonding curve and user accounts, and calculating the token amount based on the SOL amount and slippage tolerance. ```javascript const { PublicKey } = require('@solana/web3.js'); const { BN } = require('bn.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Create Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.17_activeTab=dependents Generates instructions for creating a new coin (token) on the Pump platform. This involves specifying mint, creator, user details, and metadata like name, symbol, and URI. It can also be combined with buying instructions in the same transaction. ```javascript const { PublicKey } = require('@solana/web3.js'); const { BN } = require('bn.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const instruction = await sdk.createInstruction({ mint, name: "name", symbol: "symbol", uri: "uri", creator, user, }); // or creating and buying instructions in the same tx const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.24_activeTab=code Generates instructions to buy a specified amount of a coin using SOL. It requires fetching the current state of the coin, bonding curve, and user accounts. Slippage tolerance can also be set. ```javascript const { PublicKey, Connection } = require("@solana/web3.js"); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk"); const BN = require("bn.js"); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Clone and Configure Repository as Template (Git) Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.1_activeTab=code Steps to fork and clone a GitHub repository to use as a template for a new project. Includes removing the original remote and setting up a new one, along with updating package details. ```bash # Fork this repository git clone https://github.com/pump-fun/test-common-util.git cd test-common-util git remote remove origin git remote add origin https://github.com/pump-fun/YOUR_REPO_NAME.git ``` -------------------------------- ### Sell Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=readme Generates instructions for selling a coin. Requires mint and user public keys, along with state information fetched using `fetchSellState`. Specifies the amount of tokens to sell and slippage tolerance. ```javascript const { PublicKey, Connection } = require("@solana/web3.js"); const { PumpSdk, getSellSolAmountFromTokenAmount } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve } = await sdk.fetchSellState(mint, user); const amount = new BN(15_828); const instructions = await sdk.sellInstructions({ global, bondingCurveAccountInfo, bondingCurve, mint, user, amount, solAmount: getSellSolAmountFromTokenAmount(global, bondingCurve, amount), slippage: 1, }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.22_activeTab=dependencies Generates instructions for buying coins. This requires fetching the global state and buy state for a given mint and user. It calculates the amount of tokens to buy based on the SOL amount and slippage tolerance. ```javascript const { PublicKey, Connection } = require("@solana/web3.js"); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.21.0-devnet_activeTab=dependents Generates instructions for buying a coin on the Pump protocol. This requires fetching the current state of the coin, including bonding curve and user account information. It also takes the amount of SOL to spend and slippage tolerance. ```javascript const { PublicKey, Connection } = require("@solana/web3.js"); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk"); const BN = require('bn.js'); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Generate Sell Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23_activeTab=dependents Creates instructions to sell a specified amount of a coin for SOL. Requires pre-fetched sell state, user and coin details, token amount, and slippage tolerance. Calculates SOL amounts based on token amount. ```javascript const { PublicKey, Connection } = require('@solana/web3.js'); const { PumpSdk, getSellSolAmountFromTokenAmount } = require('@pump-fun/pump-sdk'); const BN = require('bn.js'); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve } = await sdk.fetchSellState(mint, user); const amount = new BN(15_828); const instructions = await sdk.sellInstructions({ global, bondingCurveAccountInfo, bondingCurve, mint, user, amount, solAmount: getSellSolAmountFromTokenAmount(global, bondingCurve, amount), slippage: 1, }); ``` -------------------------------- ### Clone and Configure Repository as Template (Git) Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.1_activeTab=dependencies Steps to fork and clone a repository to use as a template for a new npm package. Includes removing the old origin and setting up a new one, along with updating package details. ```bash # Fork this repository # Clone the repository git clone https://github.com/pump-fun/test-common-util.git cd test-common-util # Remove the original remote git remote remove origin # Add your new repository as the origin git remote add origin https://github.com/pump-fun/YOUR_REPO_NAME.git ``` -------------------------------- ### Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.25.0-devnet_activeTab=code Generates instructions for buying a coin on the Pump platform. This requires fetching the current state of the bonding curve and user accounts. It takes the desired SOL amount and calculates the token amount to purchase, including slippage tolerance. ```javascript const { PublicKey, Connection } = require('@solana/web3.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); const { BN } = require('bn.js'); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Generate Sell Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.21.0-devnet_activeTab=dependencies Creates Solana instructions to sell a specified amount of a coin, calculating the SOL return amount and considering slippage. Requires pre-fetched state information like bonding curve details. Dependencies include PublicKey, BN.js, and PumpSdk. ```javascript const { PublicKey } = require('@solana/web3.js'); const { PumpSdk } = require('@pump-fun/pump-sdk'); const { BN } = require('bn.js'); // Assuming 'sdk' is an initialized PumpSdk instance, getSellSolAmountFromTokenAmount is available, // and state variables like global, bondingCurveAccountInfo, bondingCurve are fetched. const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve } = await sdk.fetchSellState(mint, user); const amount = new BN(15_828); const instructions = await sdk.sellInstructions({ global, bondingCurveAccountInfo, bondingCurve, mint, user, amount, solAmount: getSellSolAmountFromTokenAmount(global, bondingCurve, amount), slippage: 1, }); ``` -------------------------------- ### Initialize Pump SDK Connection Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.17_activeTab=dependents Establishes a connection to the Solana devnet and initializes the Pump SDK. This is the first step before interacting with any Pump SDK functionalities. ```javascript const { Connection } = require('@solana/web3.js'); const { PumpSdk } = require('@pump-fun/pump-sdk'); const connection = new Connection( "https://api.devnet.solana.com", "confirmed", ); const sdk = new PumpSdk(connection); ``` -------------------------------- ### Create Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.24_activeTab=code Generates instructions for creating a new coin (mint) on the Pump platform. This includes specifying coin details like name, symbol, URI, and associating creators and users. It can also be combined with buying instructions in the same transaction. ```javascript const { PublicKey, Connection } = require("@solana/web3.js"); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk"); const BN = require("bn.js"); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); // Create coin instruction only const instruction = await sdk.createInstruction({ mint, name: "name", symbol: "symbol", uri: "uri", creator, user, }); // Create and buy instructions in the same tx const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23_activeTab=dependencies Generates instructions to buy a specified amount of a coin using SOL. Requires pre-fetched buy state information, user details, and the SOL amount. Outputs an instruction array. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); // Assuming 'sdk' is an initialized PumpSdk instance and buy state is fetched const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), // Helper function needed slippage: 1, }); ``` -------------------------------- ### Fetch Buy State and Generate Buy Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23.0-devnet_activeTab=dependencies Retrieves the necessary state information (bonding curve, user accounts) for buying a specific coin and then generates the instructions to execute the purchase. Requires coin and user public keys, and the amount of SOL to spend. Dependencies include @solana/web3.js and bn.js. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); const { getBuyTokenAmountFromSolAmount } = require("@pump-fun/pump-sdk/lib/utils"); // Assuming utility path // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Create Coin Instructions with Pump SDK Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.19.0-devnet Generates instructions for creating a new coin (token) on the Solana blockchain using the Pump SDK. This function requires details like mint public key, name, symbol, URI, creator, and user public keys. It can also create and buy instructions in a single transaction. ```javascript const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const instruction = await sdk.createInstruction({ mint, name: "name", symbol: "symbol", uri: "uri", creator, user, }); // or creating and buying instructions in the same tx const global = await sdk.fetchGlobal(); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.createAndBuyInstructions({ global, mint, name: "name", symbol: "symbol", uri: "uri", creator, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, null, solAmount), }); ``` -------------------------------- ### Initialize Pump SDK Connection Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.17 Establishes a connection to the Solana devnet and initializes the PumpSdk. This is the first step before interacting with any Pump program functionalities. It requires the Solana API endpoint and a confirmation level. ```javascript const { Connection } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const connection = new Connection( "https://api.devnet.solana.com", "confirmed", ); const sdk = new PumpSdk(connection); ``` -------------------------------- ### Fetch Sell State and Generate Sell Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.23.0-devnet_activeTab=dependencies Retrieves the necessary state information for selling a specific coin and then generates the instructions to execute the sale. Requires coin and user public keys, and the amount of tokens to sell. Dependencies include @solana/web3.js and bn.js. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); const { getSellSolAmountFromTokenAmount } = require("@pump-fun/pump-sdk/lib/utils"); // Assuming utility path // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve } = await sdk.fetchSellState(mint, user); const amount = new BN(15_828); const instructions = await sdk.sellInstructions({ global, bondingCurveAccountInfo, bondingCurve, mint, user, amount, solAmount: getSellSolAmountFromTokenAmount(global, bondingCurve, amount), slippage: 1, }); ``` -------------------------------- ### Generate Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=dependents Generates instructions for buying a specified amount of a coin using SOL. This function requires pre-fetched buy state information, the coin's mint, the user's public key, and the amount of SOL to spend. Slippage tolerance can also be specified. ```javascript const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), slippage: 1, }); ``` -------------------------------- ### Sell Coin Instructions with Pump SDK Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.18_activeTab=code Generates instructions to sell a specified amount of a coin for SOL. Requires the coin's mint address, user's public key, and the amount of tokens to sell. It fetches bonding curve information to calculate the SOL amount to receive and slippage tolerance. ```javascript const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve } = await sdk.fetchSellState(mint, user); const amount = new BN(15_828); const instructions = await sdk.sellInstructions({ global, bondingCurveAccountInfo, bondingCurve, mint, user, amount, solAmount: getSellSolAmountFromTokenAmount(global, bondingCurve, amount), slippage: 1, }); ``` -------------------------------- ### Buy Coin Instructions Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.21_activeTab=dependencies Generates instructions to buy a specified amount of a coin using SOL. This requires fetching the current state of the bonding curve and associated user accounts. Slippage can be configured. ```javascript const { PublicKey } = require("@solana/web3.js"); const { PumpSdk } = require("@pump-fun/pump-sdk"); const { BN } = require("bn.js"); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const user = PublicKey.unique(); const global = await sdk.fetchGlobal(); const { bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo } = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global, bondingCurveAccountInfo, bondingCurve, associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(global, bondingCurve, solAmount), // Assuming getBuyTokenAmountFromSolAmount is available slippage: 1, }); ``` -------------------------------- ### Create Coin Instruction Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.21.0-devnet_activeTab=dependencies Generates a Solana instruction for creating a new coin (mint) with specified metadata. Requires PublicKey and BN.js. ```javascript const { PublicKey } = require('@solana/web3.js'); const { PumpSdk } = require('@pump-fun/pump-sdk'); const { BN } = require('bn.js'); // Assuming 'sdk' is an initialized PumpSdk instance const mint = PublicKey.unique(); const creator = PublicKey.unique(); const user = PublicKey.unique(); const instruction = await sdk.createInstruction({ mint, name: "name", symbol: "symbol", uri: "uri", creator, user, }); ``` -------------------------------- ### Buying Coins Source: https://www.npmjs.com/package/@pump-fun/pump-sdk/package/%40pump-fun/pump-sdk/v/1.22_activeTab=readme Provides instructions for buying coins on the Pump protocol. ```APIDOC ## Buying Coins ### Description Generates instructions to buy a specified amount of a coin on the Pump protocol. ### Method ```javascript await sdk.buyInstructions(params) ``` ### Endpoint N/A (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **global** (object) - Required - Global state object fetched from the SDK. - **bondingCurveAccountInfo** (object) - Required - Bonding curve account information. - **bondingCurve** (object) - Required - Bonding curve object. - **associatedUserAccountInfo** (object) - Required - Associated user account information. - **mint** (PublicKey) - Required - The public key of the token mint to buy. - **user** (PublicKey) - Required - The public key of the user buying the tokens. - **solAmount** (BN) - Required - The amount of SOL to spend on the purchase. - **amount** (BN) - Required - The amount of tokens to buy, calculated using `getBuyTokenAmountFromSolAmount`. - **slippage** (number) - Optional - The maximum acceptable slippage for the trade. ### Request Example ```javascript const { PublicKey, Connection } = require('@solana/web3.js'); const { PumpSdk, getBuyTokenAmountFromSolAmount } = require('@pump-fun/pump-sdk'); const { BN } = require('bn.js'); const connection = new Connection("https://api.devnet.solana.com", "confirmed"); const sdk = new PumpSdk(connection); const mint = PublicKey.unique(); const user = PublicKey.unique(); const globalState = await sdk.fetchGlobal(); const buyState = await sdk.fetchBuyState(mint, user); const solAmount = new BN(0.1 * 10 ** 9); // 0.1 SOL const instructions = await sdk.buyInstructions({ global: globalState, bondingCurveAccountInfo: buyState.bondingCurveAccountInfo, bondingCurve: buyState.bondingCurve, associatedUserAccountInfo: buyState.associatedUserAccountInfo, mint, user, solAmount, amount: getBuyTokenAmountFromSolAmount(globalState, buyState.bondingCurve, solAmount), slippage: 1, }); ``` ### Response #### Success Response (200) An array of Solana instructions for buying the coin. #### Response Example ```json // Returns an array of TransactionInstruction objects ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.