rckprtr/pumpdotfun-sdk

Bonding Curve in Devnet

Closed this issue · 11 comments

Overview

Hi again!

You mention here #27:

This was 100% built on devnet, so yes. Careful though, bonding curve is params are different.

I have the code below but get this error No bondingCurveAccount exists. I am using devnet Helius RPC. I read your SDK code and the api for getBondingCurveAccount only has two parameters. Could you please help with how to get this to work in devnet? I launched with real Sol on Pumpfun btw

Steps to Reproduce Error

  1. Launch token on Pumpfun. Does Pumpfun have devnet? I launched paying real money
  2. Run code below with correct wallet Keypair's

Error

No bondingCurveAccount exists which I print out

    if (bondingCurveAccount) {
        await buyTokens(sdk, testAccount, mint);
      } else {
        console.log("No bondingCurveAccount exists")
      }

Code

dotenv.config();

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" });
  };

getProvider()

const buyTokens = async (sdk: PumpFunSDK, testAccount: Keypair, mint: Keypair) => {
    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 main = async () => {
    try {
      const provider = getProvider();
      const sdk = new PumpFunSDK(provider);
      const connection = provider.connection;
  
      // Hardcoded keypairs for testAccount and mint
      const testAccount = Keypair.fromSecretKey(Uint8Array.from([xxxxxxxx]));

      const mint = Keypair.fromSecretKey(Uint8Array.from([xxxxxxxx]));
   
      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 buyTokens(sdk, testAccount, mint);
      } else {
        console.log("No bondingCurveAccount exists")
      }
    } catch (error) {
      console.error("An error occurred:", error);
    }
  };
  
  main();

Thanks for the code example, it helps a lot.

Did you create the bonding curve on devnet? If not, devnet and mainnet dont share the same data and you must create it there to use it.

I don't know how to create the bonding curve on devnet. Could you guide on this? I don't see docs for it

https://github.com/rckprtr/pumpdotfun-sdk/blob/main/example/basic/index.ts#L76

This function will create a token, if you pass in 0 to the buy amount it wont buy any of the token.

   const mint = Keypair.fromSecretKey(Uint8Array.from([xxxxxxxx]));
   let tokenMetadata = {
      name: "TST-7",
      symbol: "TST-7",
      description: "TST-7: This is a test token",
      file: await fs.openAsBlob("example/basic/random.png"),
    };

    let createResults = await sdk.createAndBuy(
      testAccount,
      mint,
      tokenMetadata,
      BigInt(0)
    );

LMK if you have any questions.

Please see my original post, I don't want to "create" tokens. I just want to "buy" in devnet

Please see my original post, I don't want to "create" tokens. I just want to "buy" in devnet

Well, you need to know what tokens exist on devnet, which you would need to watch for creation events. The bonding curve on devnet last I looked only fits like 5 SOL~.

To watch for token creation events use this code:
https://github.com/rckprtr/pumpdotfun-sdk/blob/main/example/events/index.ts

Im not sure of other ways of getting a list of tokens available there.

Interesting, so:

  • Pump Fun actually supports creating tokens in devent? On their website they don't have option to switch from mainnet to devnet.
  • Do know of a token in devnet we could use to buy?

Note: You also mentioned "bonding curve is params are different" so thought we needed to change your code

Yes, you can create on devnet via the blockchain as they deployed a test version of their app to it using the same address.

A token on devnet: HRkL9gEx5n1gNm2exhEFJ58faij9ShC2hyRAxEa1o8xd

Its important to know devnet has no value and when the bonding curve is complete it wont move to raydium as its all on devnet.

My code uses the Global account params on create, it pulls these params every time it creates a token. Those params are stored on the blockchain, so whatever network you are using it will use those params.

When purchasing it pulls the current bonding curve params, so it wont matter what network you are using, it will just use the params of the bonding curve.

ok thank you!

I will use your async buy function to purchase HRkL9gEx5n1gNm2exhEFJ58faij9ShC2hyRAxEa1o8xd on devnet. I'll set the Helius RPC to a devnet one as well

Really appreciate the help on this

Tried running and calling my code above to purchase HRkL9gEx5n1gNm2exhEFJ58faij9ShC2hyRAxEa1o8xd on devnet causes the failure below.

Note: my wallet in devnet has 2.5 SOL

Error

GlobalAccount {
  discriminator: xxxxx,
  initialized: true,
  authority: PublicKey [PublicKey(xxxxx)] {
    _bn: <BN: xxxxx>
  },
  feeRecipient: PublicKey [PublicKey(xxxxx)] {
    _bn: <BN: xxxxx>
  },
  initialVirtualTokenReserves: 1073000000000000n,
  initialVirtualSolReserves: 30000000000n,
  initialRealTokenReserves: 50100000000000n,
  tokenTotalSupply: 1000000000000000n,
  feeBasisPoints: 100n
}
[
  'Program ComputeBudget111111111111111111111111111111 invoke [1]',
  'Program ComputeBudget111111111111111111111111111111 failed: Computational budget exceeded'
]

Tried running and calling my code above to purchase HRkL9gEx5n1gNm2exhEFJ58faij9ShC2hyRAxEa1o8xd on devnet causes the failure below.

Note: my wallet in devnet has 2.5 SOL

Error

GlobalAccount {
  discriminator: xxxxx,
  initialized: true,
  authority: PublicKey [PublicKey(xxxxx)] {
    _bn: <BN: xxxxx>
  },
  feeRecipient: PublicKey [PublicKey(xxxxx)] {
    _bn: <BN: xxxxx>
  },
  initialVirtualTokenReserves: 1073000000000000n,
  initialVirtualSolReserves: 30000000000n,
  initialRealTokenReserves: 50100000000000n,
  tokenTotalSupply: 1000000000000000n,
  feeBasisPoints: 100n
}
[
  'Program ComputeBudget111111111111111111111111111111 invoke [1]',
  'Program ComputeBudget111111111111111111111111111111 failed: Computational budget exceeded'
]

I think you need to increase your priorityFees or remove them.

gotcha,

 {
        unitLimit: 250000,
        unitPrice: 250000,
      }

setting this made it go through. Honestly still confused with conversions in sol.

though this issue solved, went end to end. Thanks a lot again!