alchemy-sdk-js
alchemy-sdk-js copied to clipboard
Missing response error If invoking SDK rpc functions within an AWS lambda
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 (
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:
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\" ...
Anyone found an easy fix?
Can confirm this happens on nextjs 14
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs
Can confirm this happens on nextjs 14
+1
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs
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.
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);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs