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

EthersAdapter is not a constructor #287

Closed
xgambitox opened this issue Nov 12, 2022 · 8 comments
Closed

EthersAdapter is not a constructor #287

xgambitox opened this issue Nov 12, 2022 · 8 comments

Comments

@xgambitox
Copy link

Description

Trying to instantiate a new EthersAdapter from @gnosis.pm/safe-ethers-lib results in the following error:

const ethAdapter = new EthersAdapter({ ethers, signer });
                   ^

TypeError: EthersAdapter is not a constructor

Environment

  • Safe Core SDK version: 3.1.1
  • Safe Ethers lib version: 1.6.1
  • Environment:
    • Node v16.17.1

Steps to reproduce

index.js

import { ethers } from "ethers";
import EthersAdapter from "@gnosis.pm/safe-ethers-lib";

const provider = new ethers.providers.JsonRpcProvider("...");
const signer = provider.getSigner();
const ethAdapter = new EthersAdapter({ ethers, signer });

package.json

{
  ...
  "type": "module",
  ...
  "dependencies": {
    "@gnosis.pm/safe-core-sdk": "^3.1.1",
    "@gnosis.pm/safe-ethers-lib": "^1.6.1",
    "@gnosis.pm/safe-service-client": "^1.3.1",
    "ethers": "^5.7.1"
  }
}

Expected result

No error should be thrown

Additional context

Seems like a problem with module exports

@adriandelgg
Copy link

I get a similar error

@codynhat
Copy link

I am also experiencing this error.

I don't know enough about Typescript to know what's going on. Something seems to be wrong with the Typescript compilation and maybe default exports, as my compiler says this is fine, but it fails at runtime.

This is what I did as a workaround:

/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
// @ts-ignore
const ethAdapter = new EthersAdapter.default({
  ethers,
  signer
});

@xgambitox
Copy link
Author

Yes seems default exports not working as expected. Would suggest to also export them as Named Exports.

@codynhat that workaround works. Then I had similar issue with the rest of the Safe packages and had to do the same:

import EthersAdapter from "@gnosis.pm/safe-ethers-lib";
import Safe from "@gnosis.pm/safe-core-sdk";
import SafeServiceClient from "@gnosis.pm/safe-service-client";
...
const ethAdapter = new EthersAdapter.default({ ethers, signer });
const safeSdk = await Safe.default.create({ ethAdapter, safeAddress });
const safeService = new SafeServiceClient.default({ txServiceUrl, ethAdapter });

@adriandelgg
Copy link

adriandelgg commented Nov 16, 2022

import { ethers } from 'ethers';
import EthersAdapter from '@gnosis.pm/safe-ethers-lib';

const ethAdapter = new EthersAdapter({ ethers, signer });

These are the linting errors I get when I use the code above. When I do //@ts-ignore it works just fine though, so I'm not sure what the issue is.

  • OS: Linux
  • Node v16.17.1
  • Ethers.js v5.6.5
  • @gnosis.pm/safe-ethers-lib v1.6.1
(property) EthersAdapterConfig.ethers: typeof import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@gnosis.pm/safe-ethers-lib/node_modules/ethers/lib/ethers")
ethers - Ethers v5 library

Type 'typeof import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/ethers/lib/ethers")' is not assignable to type 'typeof import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@gnosis.pm/safe-ethers-lib/node_modules/ethers/lib/ethers")'.
Translation: I was expecting a type matching A, but instead you passed B.

[See full translation](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Projects
[Contribute a translation for #6255](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

The types of 'Signer.isSigner' are incompatible between these types.
[Contribute a translation for #2200](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Type '(value: any) => value is import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/providers/node_modules/@ethersproject/abstract-signer/lib/index").Signer' is not assignable to type '(value: any) => value is import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-signer/lib/index").Signer'.
Translation: I was expecting a type matching A, but instead you passed B.

[See full translation](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Type predicate 'value is Signer' is not assignable to 'value is Signer'.
[Contribute a translation for #1226](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/providers/node_modules/@ethersproject/abstract-signer/lib/index").Signer' is not assignable to type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-signer/lib/index").Signer'.
Translation: I was expecting a type matching A, but instead you passed B.

[See full translation](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Types of property 'provider' are incompatible.
[Contribute a translation for #2326](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").Provider | undefined' is not assignable to type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").Provider | undefined'.
Translation: I was expecting a type matching A, but instead you passed B.

[See full translation](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").Provider' is not assignable to type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").Provider'.
Translation: I was expecting a type matching A, but instead you passed B.

[See full translation](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

The types returned by 'getFeeData()' are incompatible between these types.
[Contribute a translation for #2201](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Type 'Promise<import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").FeeData>' is not assignable to type 'Promise<import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").FeeData>'.
Translation: I was expecting a type matching A, but instead you passed B.

[See full translation](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Property 'lastBaseFeePerGas' is missing in type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").FeeData' but required in type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").FeeData'.
Translation: You haven't passed all the required properties to import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").FeeData - import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").FeeData is missing the lastBaseFeePerGas property

[See full translation](vscode-file://vscode-app/usr/share/code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)

Type 'typeof import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/ethers/lib/ethers")' is not assignable to type 'typeof import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@gnosis.pm/safe-ethers-lib/node_modules/ethers/lib/ethers")'.
  The types of 'Signer.isSigner' are incompatible between these types.
    Type '(value: any) => value is import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/providers/node_modules/@ethersproject/abstract-signer/lib/index").Signer' is not assignable to type '(value: any) => value is import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-signer/lib/index").Signer'.
      Type predicate 'value is Signer' is not assignable to 'value is Signer'.
        Type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/providers/node_modules/@ethersproject/abstract-signer/lib/index").Signer' is not assignable to type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-signer/lib/index").Signer'.
          Types of property 'provider' are incompatible.
            Type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").Provider | undefined' is not assignable to type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").Provider | undefined'.
              Type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").Provider' is not assignable to type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").Provider'.
                The types returned by 'getFeeData()' are incompatible between these types.
                  Type 'Promise<import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").FeeData>' is not assignable to type 'Promise<import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").FeeData>'.
                    Property 'lastBaseFeePerGas' is missing in type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/abstract-provider/lib/index").FeeData' but required in type 'import("/home/codeonblocks/Documents/Projects/bp-biweekly-blockchain/frontend/node_modules/@ethersproject/contracts/node_modules/@ethersproject/abstract-provider/lib/index").FeeData'.ts(2322)
index.d.ts(85, 5): 'lastBaseFeePerGas' is declared here.
EthersAdapter.d.ts(14, 5): The expected type comes from property 'ethers' which is declared here on type 'EthersAdapterConfig'

@adriandelgg
Copy link

Yes seems default exports not working as expected. Would suggest to also export them as Named Exports.

@codynhat that workaround works. Then I had similar issue with the rest of the Safe packages and had to do the same:

import EthersAdapter from "@gnosis.pm/safe-ethers-lib";
import Safe from "@gnosis.pm/safe-core-sdk";
import SafeServiceClient from "@gnosis.pm/safe-service-client";
...
const ethAdapter = new EthersAdapter.default({ ethers, signer });
const safeSdk = await Safe.default.create({ ethAdapter, safeAddress });
const safeService = new SafeServiceClient.default({ txServiceUrl, ethAdapter });

What issues were you having with the rest of the Safe packages? When I wrote the code like on my answer above everything worked fine for me.

@germartinez
Copy link
Member

germartinez commented Nov 16, 2022

Hi @xgambitox, @adriandelgg and @codynhat
Does any of you have your project available on Github so I can test some changes in the SDK to fix this issue?
Thank you!

@xgambitox
Copy link
Author

Hi @xgambitox, @adriandelgg and @codynhat Does any of you have your project available on Github so I can test some changes in the SDK to fix this issue? Thank you!

Hi @germartinez, created this minimal repo here so you are able to reproduce it.

Thanks for looking into it.

@yagopv
Copy link
Member

yagopv commented Aug 30, 2023

Hey @xgambitox. The issue is you are using node.js with ESM Modules and we are compiling the core as commonjs. This is a known issue and we opened a ticket to address this. The default workaround works btw for now or you can remove the "type": "module", from the package.json as well

@yagopv yagopv closed this as completed Aug 30, 2023
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

5 participants