alchemy-sdk-js icon indicating copy to clipboard operation
alchemy-sdk-js copied to clipboard

Missing response error If invoking SDK rpc functions within an AWS lambda

Open nsatharasinghe opened this issue 1 year ago • 5 comments

Environment

AWS Lambda

  • Browser version: n/a
  • Alchemy SDK version: 3.1.0

Describe the problem

Missing response error If invoking SDK rpc functions within an AWS Lambda

missing response (requestBody="{"method":"eth_gasPrice","params":[],"id":42,"jsonrpc":"2.0"}", requestMethod="POST", serverError={}, url="https://eth-sepolia.g.alchemy.com/v2/{API-KEY}, code=SERVER_ERROR, version=web/5.7.1) at Logger.makeError (/var/task/src/webpack:/node_modules/@ethersproject/logger/lib.esm/index.js:224:1) at Logger.throwError (/var/task/src/webpack:/node_modules/@ethersproject/logger/lib.esm/index.js:233:1) at /var/task/src/webpack:/node_modules/@ethersproject/web/lib.esm/index.js:217:1 at Generator.throw () at rejected (/var/task/src/webpack:/node_modules/@ethersproject/web/lib.esm/index.js:6:42) at processTicksAndRejections

How to reproduce:

Use the below code within an AWS lambda:

import { Alchemy, Network } from 'alchemy-sdk';

 const settings = {
            apiKey: 'api-key',
            network: Network.ETH_SEPOLIA,
        };

        const alchemy = new Alchemy(settings);
        try {
            const gp = await alchemy.core.getGasPrice();
            Logger.info('AlchemyTestHandler getGasPrice >>>', gp);
        } catch (error) {
            Logger.info('AlchemyTestHandler error', error);
        }

Relevant code or sample repro:

nsatharasinghe avatar Dec 15 '23 09:12 nsatharasinghe

This will also happen when using nextjs v14 ssr as below.

import { Alchemy, Network } from "alchemy-sdk";

export default async function Home() {
  const alchemy = new Alchemy({
    apiKey: "",
    network: Network.ETH_MAINNET,
  });

  const blockNumber = await alchemy.core.getBlockNumber();

  return (
    <main className="flex min-h-screen flex-col items-center justify-between p-24">
      <div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
        <p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto  lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
          {blockNumber}
        </p>
      </div>
    </main>
  );
}
Error: missing response (requestBody="{\"method\":\"eth_blockNumber\" ...

ChiuMungZitAlexander avatar Dec 29 '23 09:12 ChiuMungZitAlexander

Anyone found an easy fix?

leonacostaok avatar Jan 05 '24 03:01 leonacostaok

Can confirm this happens on nextjs 14

smblee avatar Jan 28 '24 18:01 smblee

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs

github-actions[bot] avatar Feb 28 '24 01:02 github-actions[bot]

Can confirm this happens on nextjs 14

+1

alexkubica avatar Apr 06 '24 07:04 alexkubica

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs

github-actions[bot] avatar May 07 '24 01:05 github-actions[bot]

I've added support for passing in a ConnectionInfo override via the AlchemySettings.connectionInfoOverrides property in v3.3.1 of the SDK. You should be able to follow the comments in this ethers thread and pass in skipFetchSetup or your own fetchOptions object to work around the issue.

thebrianchen avatar May 08 '24 16:05 thebrianchen

here is an example using @thebrianchen override workaround, this works in nextjs 14

const config = {
  apiKey: process.env.ALCHEMY_API, // Replace with your API key
  network: Network.BASE_MAINNET, // Replace with your network
  connectionInfoOverrides: {
    skipFetchSetup: true,
  },
} as AlchemySettings;

const alchemy = new Alchemy(config);

rsproule avatar Jun 06 '24 03:06 rsproule

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs

github-actions[bot] avatar Jul 07 '24 01:07 github-actions[bot]