rckprtr / pumpdotfun-sdk

PumpDotFun SDK
MIT License
278 stars 120 forks source link

https://pump.fun/api/ipfs returning 500 #34

Closed mishanefedov closed 3 months ago

mishanefedov commented 3 months ago

The createAndBuy function uses https://pump.fun/api/ipfs to create token Metadata, and the endpoint returns 500 code. Is there another way to create tokens on Pumpfun? Or to manually generate the token Metadata?

https://github.com/rckprtr/pumpdotfun-sdk/blob/3f38ca32609ccc4d2a78a7ecfcb357648dee387b/src/pumpfun.ts#L405

rckprtr commented 3 months ago

I just checked, it should be working, is it possible the upload failed or your values are incorrect?

mishanefedov commented 3 months ago

I just checked, it should be working, is it possible the upload failed or your values are incorrect?

Thanks! I was able to solve my issue by manually creating the Blob file. Here is the code snippet:

  private async deployAndSnipe() {
    try {
      const mint = this.getOrCreateKeypair('./pumpfunKeys', 'mint');
      const filePath = 'random.png';
      const fileBlob = await this.createBlobFromFile(filePath);
      const tokenMetadata: CreateTokenMetadata = {
        name: 'TST-7',
        symbol: 'TST-7',
        description: 'TST-7: token',
        file: fileBlob,
      };

      const createResult = await this.pumpfunSDK.createAndBuy(
        this.keypair,
        mint,
        tokenMetadata,
        BigInt(0.0001 * LAMPORTS_PER_SOL),
        SLIPPAGE_BASIS_POINTS,
        {
          unitLimit: 250000,
          unitPrice: 250000,
        },
      );
    } catch (error) {
      console.error(`Pumpfun Sniper Error in deployAndSnipe(): ${error}`);
    }
  }

  private async createBlobFromFile(filePath: string): Promise<Blob> {
    return new Promise((resolve, reject) => {
      fs.readFile(filePath, (err, data) => {
        if (err) {
          return reject(err);
        }
        const blob = new Blob([data]);
        resolve(blob);
      });
    });
  }

Previously, I used

const tokenMetadata = {
    name: 'TST-7',
    symbol: 'TST-7',
    description: 'TST-7: token',
    file: 'path/to/file',
  };

as in the example.

My previous code was failing here. I may be missing something, but I did not find where the tokenMetadata is converted to CreateTokenMetadata.

rckprtr commented 3 months ago

It should be passed in as the Type, but yes the file path needs to be correct. I could have better error handling here.