2

I've been trying to use the @solana/web3.js library to send RPC requests for transaction data but I'm getting hit with the following error:

Error: 429 Too Many Requests: {"jsonrpc":"2.0","error":{"code": 429, "message":"Too many requests for a specific RPC call, contact your app developer or [email protected]."}

I've realized that the solution lies in the Retry-After HTTP response header. I have to obtain this header to know how long I need to wait for the rest of the requests to execute properly without error. My only problem is that I don't know how to access this response header in @solana/web3.js.

Here are the requests:

function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }

async function rpcRequests() {
  try {
    const Signatures = await connection.getSignaturesForAddress(address, options);
    Signatures.forEach(signature => {
        if (signature && signature.signature && signature.err === null) {
            SignaturesArray.push(signature.signature);
        }
    });

    await delay(1000);

    const Transactions = await connection.getParsedTransactions(SignaturesArray, GetVersionedTransactionConfig);
    Transactions.forEach(transaction => {
        if (transaction && transaction.transaction && transaction.transaction.message && transaction.transaction.message.instructions) {
            const instructions = transaction.transaction.message.instructions;
            instructions.forEach(instruction => {
                console.log(instruction);
                }
            })
        }
    })
  } catch (error) {
    console.error('Error: ' + error);
  }
}

rpcRequests();

(I'm only showing a portion of the code, there are 6 more requests that need to be sent)

1

1 Answer 1

-1

If you're currently using the public rpc and getting rate limited, try signing up for a free helius account and use a custom rpc endpoint. https://www.helius.dev/

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.