2

I am trying to make a batch request for getAssetTransfers endpoint.

However, when I try to do this, I get this error:

    jsonrpc: '2.0',
    id: 1,
    error: {
      code: -32600,
      message: 'Unsupported methods [alchemy_getAssetTransfers] in batch call. See available methods at https://docs.alchemy.com/alchemy/documentation/apis'
    }
  }

Is it not possible to batch this request? I cannot find the list of supported requests over HTTP anywhere in their documentation. This is the code I have:

async function batchAlchemyTxnRequests(fromBlockNumber, address1, address2) {
    let fromBlockNumberInHex = "0x" + fromBlockNumber.toString(16);

    let req1 = {
        method: 'alchemy_getAssetTransfers',
        params: [
            {
                fromBlock: fromBlockNumberInHex,
                toBlock: 'latest',
                toAddress: address1,
                category: ['erc721', 'erc1155', 'specialnft'],
                withMetadata: true,
                excludeZeroValue: true,
            },

        ],
        id: 1,
        jsonrpc: '2.0'
    };
    let req2 = {
        method: 'alchemy_getAssetTransfers',
        params: [
            {
                fromBlock: fromBlockNumberInHex,
                toBlock: 'latest',
                fromAddress: address2,
                category: ['erc721', 'erc1155', 'specialnft'],
                withMetadata: true,
                excludeZeroValue: true,
            },
        ],
        id: 2,
        jsonrpc: '2.0'
    };

    let reqs = [req1, req2];
    let baseUrl = 'https://eth-mainnet.g.alchemy.com/v2/'+config.ALCHEMY_API_KEY;

    const res = await fetch(
        baseUrl, {
            method: 'POST', 
            body: JSON.stringify(reqs), 
            headers: {
                'Content-Type': 'application/json'
            }
        }
    ).catch (err => console.log(err));
    const data = await res.json();
    console.log(data);
}

I am trying to get ethereum-mainnet transactions for a list of addresses through the API, if that helps.

1 Answer 1

0

This is Killiane from Alchemy, I am following my answers from your ticket in the Alchemy Discord server here!

Unfortunately we currently do not support batching for our enhanced APIs, alchemy_ methods like alchemy_getAssetTransfers cannot be batched. Also debug_ and trace_ methods cannot be batched either.

There is some workaround that would allow you to get similar data to _getAssetTransfers since asset transfers data is derived from:

Both eth_blockByNumber and eth_getLogs can be batched I believe (or, at least in the case of logs, you can do from/to block ranges). However, there’s no way to batch traces right now! But it’s some more work to interpret the responses of these endpoints and convert into transfer events I would say.

As we are constantly upgrading our products, your feedback is super valuable to us and we will work on integrating your feature-request into our roadmap! 🙏

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.