ethers-io / ethers-web3-bridge Goto Github PK
View Code? Open in Web Editor NEWAllow Web3 instances to connect and use Ethers Providers and Signers.
Allow Web3 instances to connect and use Ethers Providers and Signers.
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!
ProvideBridge
's constructor sets up an interval here that is impossible to stop and doesn't let node processes finish.
Running this script in node is enough to reproduce the problem:
const ProviderBridge = require('ethers-web3-bridge');
new ProviderBridge();
The expected behavior is that the process finishes right after instantiating ProviderBridge
, but it never does.
This could be fixed by adding some method to clear that interval, but IMO that would cripple ProviderBridge
's API, as it won't be usable in a fire-and-forget scenario.
But I don't see a clear need for having that interval, can't the address be updated right after setting the signer here.
There's also this functionality, which may return an outdated address if the proposed change is implemented, but that's already happening.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.