ethers-web3-bridge
ethers-web3-bridge copied to clipboard
Signer.getAddress() is not a function
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!
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. :)
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')
.
Hey @ricmoo , just bouncing this thread. Thanks!
Heya! I’ve started porting the bridge to v4., but thanks for the reminded, I’ll try to get it finished this week. :)
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?
You want the Eip1193Bridge. It’s still experimental, but I’ve used it a few times. :)
(I need to add more documentation for it; the parameters are flipped compared to this old repo, new Eip1193Provider(signer, provider)
)
Thank you so much Ric, will take a look at it :)
No worries. I'll archive this project and add a link to the readme to the above package. :)
@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.
This repo is deprecated; please see the v5 docs instead.