Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Signer.getAddress() is not a function #3

Open
pakaplace opened this issue Sep 14, 2018 · 11 comments
Open

Signer.getAddress() is not a function #3

pakaplace opened this issue Sep 14, 2018 · 11 comments

Comments

@pakaplace
Copy link

pakaplace commented Sep 14, 2018

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!

@ricmoo
Copy link
Member

ricmoo commented Sep 15, 2018

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. :)

@pakaplace
Copy link
Author

pakaplace commented Sep 18, 2018

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
Copy link
Author

Hey @ricmoo , just bouncing this thread. Thanks!

@ricmoo
Copy link
Member

ricmoo commented Oct 20, 2018

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

@Tbaut
Copy link

Tbaut commented Apr 30, 2021

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?

@ricmoo
Copy link
Member

ricmoo commented Apr 30, 2021

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

@ricmoo
Copy link
Member

ricmoo commented Apr 30, 2021

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

@Tbaut
Copy link

Tbaut commented Apr 30, 2021

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

@ricmoo
Copy link
Member

ricmoo commented May 1, 2021

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

@sandys
Copy link

sandys commented Oct 1, 2021

@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.

@ricmoo
Copy link
Member

ricmoo commented Oct 1, 2021

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

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

No branches or pull requests

4 participants