Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined: getAddress when querying for CounterFactual address #45

Closed
therealharpaljadeja opened this issue Jul 5, 2023 · 3 comments · Fixed by #90
Labels
bug Something isn't working no-issue-activity

Comments

@therealharpaljadeja
Copy link
Contributor

[REQUIRED] Environment

image
  • Browser version: Chrome - 114.0.5735.198
  • AA SDK version: 0.1.0-alpha.14
  • Package: alchemy/aa-core

[REQUIRED] Describe the problem

When someone tries to query for the CounterFactual address of the SimpleSmartContractAccount then the error Cannot read properties of undefined: getAddress is thrown

How to reproduce:

let provider = new SmartAccountProvider(
      "[rpc_url]",
      ENTRYPOINT_ADDRESS,
      sepolia
).connect((rpcClient) => {
    return new SimpleSmartContractAccount({
        entryPointAddress: ENTRYPOINT_ADDRESS,
        chain: sepolia,
        factoryAddress: SIMPLE_ACCOUNT_FACTORY_ADDRESS,
        rpcClient,
        owner: customClient,
    });
});

// Trying to query for the CounterFactual address of Smart Account
let address = await provider.account.getAddress();
@therealharpaljadeja therealharpaljadeja added the bug Something isn't working label Jul 5, 2023
@therealharpaljadeja
Copy link
Contributor Author

Solution

This problem is caused because aa-sdk uses viem behind the scenes and when I am using rainbowkit connected wallet as my owner to the SimpleSmartContractAccount, it passes down the Wallet Client

Wallet Client has no getAddress method which is the root cause of the above error.

image

However, Wallet Client can be extended using the following code:

const { data: walletClient } = useWalletClient();
let newClient = walletClient.extend((client) => {
      return {
          getAddress: async function () {
              let addresses = await client.getAddresses();
              return addresses[0];
          },
      };
  })

The newClient in the above code will have the getAddress method which can then be used as the owner for SimpleSmartContractAccount like so

let provider = new SmartAccountProvider(
      "[rpc_url]",
      ENTRYPOINT_ADDRESS,
      sepolia
  ).connect((rpcClient) => {
      return new SimpleSmartContractAccount({
          entryPointAddress: ENTRYPOINT_ADDRESS,
          chain: sepolia,
          factoryAddress: SIMPLE_ACCOUNT_FACTORY_ADDRESS,
          rpcClient,
          owner: newClient,
      });
  });

You can also check out my project using this

@moldy530
Copy link
Collaborator

moldy530 commented Jul 5, 2023

@therealharpaljadeja Thanks for this summary! I'm actually going to re-open the issue so that we can add a utility to handle this in the future for others

@moldy530 moldy530 reopened this Jul 5, 2023
@github-actions
Copy link

github-actions bot commented Aug 5, 2023

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

rthomare pushed a commit that referenced this issue Oct 4, 2023
docs: update the docs on byosca to use LightAccount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working no-issue-activity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants