ethers-web3-bridge icon indicating copy to clipboard operation
ethers-web3-bridge copied to clipboard

Signer.getAddress() is not a function

Open pakaplace opened this issue 6 years ago • 11 comments

Hi there!

First off, thank you so much for Ethers.js. I use it as much as possible throughout my app. I recently used it to automating contract deployment and account funding on test-rpc, which cut down our setup time for testing by at least an hour. I'll be sharing gists soon to help others, and plan on demonstrating ethers in a hackathon I'm mentoring at this fall.

Now, I'm trying to do injected web3 Dapp testing with Cypress, an end-to-end javascript testing framework similar to selenium.

cy.on('window:before:load', async(win) => {
        var provider = new ethers.providers.getDefaultProvider('rinkeby')
        var wallet = new ethers.Wallet(process.env.PK)
        let providerBridge = new ProviderBridge(provider, wallet)
        console.log("Provider bridge", providerBridge) // Provider and Signer are properly set
        win.web3 = new Web3(providerBridge)
        win.web3.eth.getBlockNumber((err, res) => {
          console.log("result,", res)
        })
        win.web3.eth.getAccounts().then(console.log)
        win.web3.eth.getAccounts((err, accounts) => {console.log(accounts)})
      })

window.web3 is setting properly^^

I create a web3 instance and log it out, isConnected is true and signer is set with the correct address. However, when I call win.web3.eth.getAccounts(), I encounter the error signer.getAddress() is not a function. The error is occurring in line 337 of this module's index.js. web3.eth.getBlockNumber()`, which does not require a signer, is working as it should.

For more context, please see this article on web3 integration tests . Note that I could not replicate the code this author used in his example with truffle-privatekey-provider.

I've tried using your .connectEthers(Provider, Signer) method as well.

Thanks for your help!

pakaplace avatar Sep 14 '18 21:09 pakaplace

Is this on v3 or v4 of ethers? I will be overhauling the bridge soon for v4...

I’ll look more into getting this updated this week. :)

ricmoo avatar Sep 15 '18 15:09 ricmoo

It's 3.0.27, and thanks! I also saw this question you answered and (naively) tried to set the wallet's provider manually (e.g. wallet.provider = ethers.providers.JsonRpcProvider('localhost:3000').

pakaplace avatar Sep 18 '18 01:09 pakaplace

Hey @ricmoo , just bouncing this thread. Thanks!

pakaplace avatar Oct 20 '18 13:10 pakaplace

Heya! I’ve started porting the bridge to v4., but thanks for the reminded, I’ll try to get it finished this week. :)

ricmoo avatar Oct 20 '18 16:10 ricmoo

This issue is very old, and it looks like ethers-web3-bridge is not actively maintained, but the use case holds. I'd like to do exactly the same thing @pakaplace. To test a Dapp with Cypress, I would like to mock Metamask, and be able to programmatically sign messages or transactions with ethers. Did you achieve this? Any pointer to how this would be feasible?

Tbaut avatar Apr 30 '21 13:04 Tbaut

You want the Eip1193Bridge. It’s still experimental, but I’ve used it a few times. :)

ricmoo avatar Apr 30 '21 13:04 ricmoo

(I need to add more documentation for it; the parameters are flipped compared to this old repo, new Eip1193Provider(signer, provider))

ricmoo avatar Apr 30 '21 13:04 ricmoo

Thank you so much Ric, will take a look at it :)

Tbaut avatar Apr 30 '21 14:04 Tbaut

No worries. I'll archive this project and add a link to the readme to the above package. :)

ricmoo avatar May 01 '21 00:05 ricmoo

@ricmoo @Tbaut is there any minimal example with the new Eip1193Provider ? i wasnt able to find the equivalent for an injected in-page provider using rinkeby.

sandys avatar Oct 01 '21 10:10 sandys

This repo is deprecated; please see the v5 docs instead.

ricmoo avatar Oct 01 '21 10:10 ricmoo