ensdomains / ensjs-v2

Javascript bindings for the Ethereum Name Service
208 stars 122 forks source link

ENS constructor calls getSigner() even when provider doesn't implement it #77

Open brendandebeasi opened 2 years ago

brendandebeasi commented 2 years ago

Take the code

    const provider = new EtherscanProvider('homestead', 'APIKEY')
    const ens = new ENS({ provider, ensAddress: getEnsAddress(1) })
    ens.name('resolver.eth').getAddress() // 0x123
    let address = await ens.name('resolver.eth').getAddress()

Will fail on line 2 with no method exists getSigner()

Called on line node_modules/@ensdomains/ensjs/dist/index.js:1035

...
    this.provider = ethersProvider;
    this.signer = ethersProvider.getSigner();
    this.ens = getENSContract({
      address: ensAddress ? ensAddress : registries[networkId],
      provider: ethersProvider
    });
...

Solution is to only set this.signer if the provider implements it.

grepfruit19 commented 2 years ago

I'm also running into this problem. I use ensjs solely for lookups, so this makes the library unusable for my purposes.

grepfruit19 commented 2 years ago

I've been able to get it to work by just adding a getSigner() property that does nothing:

  const provider = new ethers.providers.InfuraProvider('mainnet', {});
  provider.getSigner = () => {};