pumpdotfun-sdk icon indicating copy to clipboard operation
pumpdotfun-sdk copied to clipboard

Cannot read properties of undefined (reading 'file')

Open tmcrypted opened this issue 1 year ago • 4 comments

I have error with BLOB pls help me

I can't use readAsBlob

try {

    const fileBuffer = fs.readFileSync('tiho2.png');
    const fileBlob = new Blob([fileBuffer], { type: 'image/png' });

    console.log(fileBlob instanceof Blob);
    console.log(typeof fileBlob);
    console.log(fileBlob);

    const mint = Keypair.generate();
    const buyAmountSol = BigInt(0.00001 * 10 ** 9);


    const transactionResult = await pumpClient.createAndBuy({
        creator: wallet,
        mint: mint,
        createTokenMetadata: {
            name: 'my bobus token',
            symbol: 'BBS',
            description: 'my bobus token',
            file: fileBlob,
        },

        buyAmountSol: buyAmountSol,
        slippageBasisPoints: 250,
        priorityFees: {
            unitLimit: 1000000,
            unitPrice: 5000
        },
        commitment: 'confirmed',
        finality: 'finalized'
    });
    console.log('token created :', transactionResult);
} catch (error) {
    console.error('err when creating:', error);
}

PS C:\Users\prayer\Desktop\pumpfun> node .\create.js true object Blob { size: 13937, type: 'image/png' } err when creating: TypeError: Cannot read properties of undefined (reading 'file') at PumpFunSDK.createTokenMetadata (C:\Users\prayer\Desktop\pumpfun\node_modules\pumpdotfun-sdk\dist\cjs\pumpfun.js:148:40) at PumpFunSDK.createAndBuy (C:\Users\prayer\Desktop\pumpfun\node_modules\pumpdotfun-sdk\dist\cjs\pumpfun.js:28:40) at createToken (file:///C:/Users/prayer/Desktop/pumpfun/create.js:29:52) at file:///C:/Users/prayer/Desktop/pumpfun/create.js:55:1 at ModuleJob.run (node:internal/modules/esm/module_job:222:25) at async ModuleLoader.import (node:internal/modules/esm/loader:316:24) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)

tmcrypted avatar Nov 06 '24 09:11 tmcrypted

It needs to be used in node.js

Gtokentool avatar Nov 08 '24 03:11 Gtokentool

It needs to be used in node.js

it's node js :( idk what to do

` import bs from 'bs58'; import { Keypair, Connection } from '@solana/web3.js'; import { PumpFunSDK } from 'pumpdotfun-sdk'; import { AnchorProvider } from '@coral-xyz/anchor'; import fs from 'fs';

const connection = new Connection('', 'confirmed');

const wallet = Keypair.fromSecretKey(bs.decode(''));

const provider = new AnchorProvider(connection, wallet, { commitment: "finalized" }); const pumpClient = new PumpFunSDK(provider);

const createToken = async () => { try {

    const fileBuffer = fs.readFileSync('tiho2.png');
    const fileBlob = new Blob([fileBuffer], { type: 'image/png' });

    console.log(fileBlob instanceof Blob);
    console.log(typeof fileBlob);
    console.log(fileBlob);

    const mint = Keypair.generate();
    const buyAmountSol = BigInt(0.00001 * 10 ** 9);


    const transactionResult = await pumpClient.createAndBuy({
        creator: wallet,
        mint: mint,
        createTokenMetadata: {
            name: 'my bobus token',
            symbol: 'BBS',
            description: 'my bobus token',
            file: fileBlob,
        },

        buyAmountSol: buyAmountSol,
        slippageBasisPoints: 250,
        priorityFees: {
            unitLimit: 1000000,
            unitPrice: 5000
        },
        commitment: 'confirmed',
        finality: 'finalized'
    });
    console.log('token created :', transactionResult);
} catch (error) {
    console.error('err when creating:', error);
}

};

const main = async () => { await createToken(); };

main(); `

tmcrypted avatar Nov 10 '24 12:11 tmcrypted

cloudflare? mb problem?

tmcrypted avatar Nov 10 '24 12:11 tmcrypted

Instead of using "fs" to read files, try using "fetch"

Gtokentool avatar Nov 11 '24 02:11 Gtokentool