Hello im trying to make a bot that gets token metadata for the latest minted tokens on the solana blockchain. However whenever I run it I keep getting this error

Error: Unknown https cluster: mainnet

I tried to put the address there instead of just mainnet but that did not work either. This is my code below

const { Connection, clusterApiUrl } = require('@solana/web3.js');
const { TOKEN_PROGRAM_ID, Token } = require("@solana/spl-token");

async function main() {
    try {
        //  connection to the mainnet cluste
        const connection = new Connection(clusterApiUrl('mainnet'), 'confirmed');

        // Fetches the blockhash (so we get the latest data as we are using the latest blockhash)
        const { blockhash } = await connection.getLatestBlockhash();

        // Fetch recent transactions on the block
        const block = await connection.getBlock(blockhash);

        // Get da token account addresses from transactions
        const tokenAccountAddresses = block.transactions.flatMap(tx => {
            return tx.transaction.message.accountKeys
                .filter(acc => acc.equals(TOKEN_PROGRAM_ID))
                .map(acc => tx.transaction.message.accountKeys[acc.equals(TOKEN_PROGRAM_ID) ? 1 : 0].toBase58());

        // Gets unique token mint addresses
        const mintAddresses = [...new Set(tokenAccountAddresses)];

        // Fetches token metadata for each mint
        for (let i = 0; i < Math.min(mintAddresses.length, 5); i++) {
            const token = new Token(connection, mintAddresses[i], TOKEN_PROGRAM_ID, null);

            // Fetch all token metadata
            const tokenInfo = await token.getMintInfo();
            console.log(`Token Metadata for ${mintAddresses[i]}:`);
    } catch (error) {
        console.error("Error fetching the tokens metadata:", error);


This is the complete error:

bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?) Error fetching the tokens metadata: Error: Unknown https cluster: mainnet at clusterApiUrl (C:\Users\rayof\node_modules@solana\web3.js\lib\index.cjs.js:10992:11) at main (C:\Users\user\OneDrive\Desktop\Solana sniper\solana.js:7:43) at Object. (C:\Users\user\OneDrive\Desktop\Solana sniper\solana.js:39:1) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49

I would appreciate if anyone could help me on fixing this, im completely new to all of this


1 Answer 1


The actual moniker for Solana mainnet is "mainnet-beta", so inputting that should work.

Additionally, "https://api.mainnet-beta.solana.com/" should work as well.

  • Thank you so much! it worked now im not getting that error. I do have a different one now but ill try looking that up before asking here
    – Golden
    Commented May 9 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.