TypeError: Cannot read properties of undefined (reading 'http')
Haavi97 opened this issue · comments
Haavi commented
[REQUIRED] Environment
- Browser version: Opera 107 on Windows 11
- AA SDK version: 3.4.2
- Package: aa-accounts
[REQUIRED] Describe the problem
When I try to get Alchemy Rpc client I get the following error:
TypeError: Cannot read properties of undefined (reading 'http')
at createAlchemyPublicRpcClient (rpcClient.js:15:86)
at createLightAccountAlchemyClient (lightAccountClient.js:19:95)
at connectProvider (useAAProvider.jsx:33:59)
at async getProvider (index.jsx:80:24)
```
#### How to reproduce:
Problem seems to be in function `createLightAccountAlchemyClient`
Code snippet :
```javascript
import { createWalletClient, custom, http } from "viem";
import { WalletClientSigner } from "@alchemy/aa-core";
import { createLightAccountAlchemyClient } from "@alchemy/aa-alchemy";
import { createLightAccount } from "@alchemy/aa-accounts";
import { polygonMumbai } from "viem/chains";
export const rpcTransport = http(process.env.NEXT_PUBLIC_RPC_URL);
const chain = polygonMumbai;
function useAAProvider() {
const createEOASigner = () => {
const walletClient = createWalletClient({
chain,
transport: custom(window.ethereum),
});
const eoaSigner = new WalletClientSigner(
walletClient,
"json-rpc" //signerType
);
return eoaSigner;
};
const connectProvider = async (scaAddress) => {
const eoaSigner = createEOASigner();
const provider = await createLightAccountAlchemyClient({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
chain,
signer: eoaSigner,
account: await createLightAccount({
transport: rpcTransport,
chain,
signer: eoaSigner,
accountAddress: scaAddress ? scaAddress : undefined,
}),
});
return provider;
};
return { connectProvider };
}
export default useAAProvider;
```
I have also tried to add:
```javscript
connectionConfig: {
rpcUrl: process.env.NEXT_PUBLIC_RPC_URL,
},
```
but that didn't solve the issue.
Michael Moldoveanu commented
there's a bug in this syntax. the account
param should be an object not an instance
Change:
const provider = await createLightAccountAlchemyClient({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
chain,
signer: eoaSigner,
account: await createLightAccount({
transport: rpcTransport,
chain,
signer: eoaSigner,
accountAddress: scaAddress ? scaAddress : undefined,
}),
});
to:
const provider = await createLightAccountAlchemyClient({
apiKey: process.env.NEXT_PUBLIC_ALCHEMY_API_KEY,
chain,
account: {
transport: rpcTransport,
chain,
signer: eoaSigner,
accountAddress: scaAddress ? scaAddress : undefined,
},
});
Haavi commented
Thank you for the quick response!
Unfortunately, that doesn't solve the issue. The same error still appears and also that code was pretty much taken from the documentation like here
Haavi commented
Updated everything to 3.5.1. and some other changes and that error disappeared. Probably it was some conflict between versions.
The main difference was using createSmartAccountClient
instead of createLightAccountAlchemyClient