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

detectProxyTarget is not a function #6

Open
xluckydegen opened this issue Dec 2, 2022 · 9 comments
Open

detectProxyTarget is not a function #6

xluckydegen opened this issue Dec 2, 2022 · 9 comments

Comments

@xluckydegen
Copy link

Hi,
I'm trying to use your library in nodejs 18.12.0 but I still receiving the following error during runtime:

detectProxyTarget is not a function

I'm including your library in this way:

import detectProxyTarget from "evm-proxy-detection";

and using it this way:

  static async isProxy(networkAccessManager: EthersNetworkAccessManager, address: string)
  {
    const provider = networkAccessManager.getReadOnlyProvider();
    const requestFunc = (args: RequestArguments) => provider.send(args.method, args.params);
    const target = await detectProxyTarget(
      address,
      requestFunc
    )
    console.log(target) // logs "0x4bd844F72A8edD323056130A86FC624D0dbcF5b0" 
    return target;
  }

Do you have any idea why the import is not working? Thanks for any advice

@xluckydegen
Copy link
Author

When I downloaded your library directly from the GitHub and import it into my project everything is working fine. So it's probably some issue in the distribution package (I'm using Yarn)

@mmv08
Copy link
Contributor

mmv08 commented Dec 3, 2022

Could you please post here the result of console.log(detectProxyTarget)

@xluckydegen
Copy link
Author

Code_2022-12-03_14-00-26

@xluckydegen
Copy link
Author

Code_2022-12-03_18-03-47

(This is what I see when using your library directly from GitHub instead of the npm/yarn version)

@mmv08
Copy link
Contributor

mmv08 commented Dec 6, 2022

Code_2022-12-03_14-00-26

The library is exported as a CommonJS module but Node.js expects an ECMAScript Module. It is interoperable but requires some magic. Please read this Node.js docs section https://nodejs.org/api/esm.html#interoperability-with-commonjs

@catalyst17
Copy link

catalyst17 commented Dec 8, 2022

Had the same issue, the easiest solution for me was to switch to ts-node

Or, at least, it started "working". Returning null even for the example contract. Weird

@zilayo
Copy link

zilayo commented Mar 10, 2023

Same issue here.

2 workarounds that are working for me:

import detectProxyTarget from "evm-proxy-detection";
const { default: detectProxy } = detectProxyTarget

...

const target = await detectProxy(
  '0xA7AeFeaD2F25972D80516628417ac46b3F2604Af',
  requestFunc
)
console.log(target) // logs "0x4bd844F72A8edD323056130A86FC624D0dbcF5b0"

import detectProxyTarget from "evm-proxy-detection";

...

const target = await detectProxy.default(
  '0xA7AeFeaD2F25972D80516628417ac46b3F2604Af',
  requestFunc
)
console.log(target) // logs "0x4bd844F72A8edD323056130A86FC624D0dbcF5b0"

@xluckydegen
Copy link
Author

Unfortunately, this doesn't work for me :-(

error TS2339: Property 'default' does not exist on type '(proxyAddress: string, jsonRpcRequest: EIP1193ProviderRequestFunc, blockTag?: BlockTag | undefined) => Promise<string | null>'.

@xluckydegen
Copy link
Author

I figured it out, in the case of typescript it's necessary to do cast:

    const target = await (<any>detectProxyTarget).default(
      address,
      requestFunc,
      "latest"
    );

Thanks for the hint @Zil-B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants