Add support for ethers.js v5
See original GitHub issueethers.js v5 is currently in beta, but I’ve used it with other providers such as MetaMask and haven’t had any issues with it. However, it seems Magic does not support ethers v5, as the following steps produced the error shown when using ethers 5.0.0-beta.186 but not when using ether v4.
This error showed up when loading the page. If you ignored it and proceeded to use the provider and signer, you would find they are invalid and unable to send transactions or read contract data. The resulting error in this case is similar the one below, but with a method of eth_accounts
instead of eth_chainId
The Error
Steps to Reproduce
Relevant portions shown below
// ConnectWallet.vue ===========================================
// Initialize Magic
const magic = new Magic(process.env.MAGIC_API_KEY, { network: 'kovan' });
magic.preload();
// Check if user is logged in
const isLoggedIn = await magic.user.isLoggedIn();
if (isLoggedIn) {
await this.$store.dispatch('main/setEthereumData', magic);
return
}
// If not logged in, log them in
await magic.auth.loginWithMagicLink({ email: this.email });
await this.$store.dispatch('main/setEthereumData', magic);
// Contents of the `setEthereumData` action ======================
export async function setEthereumData({ commit }, magic) {
const provider = magic.rpcProvider;
const ethersProvider = new ethers.providers.Web3Provider(provider);
const signer = ethersProvider.getSigner();
const metadata = await magic.user.getMetadata();
const { email, publicAddress } = metadata;
})
🌎 Environment
Software | Version(s) |
---|---|
magic-sdk |
1.3.2 |
ethers.js |
5.0.0-beta.186 (did not work) and 4.0.47 (worked) |
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Ethers.js
The ethers.js library aims to be a complete and compact library for interacting with the Ethereum Blockchain and its ecosystem. It was originally...
Read more >ethers-io/ethers.js: Complete Ethereum library and ... - GitHub
Ethers works closely with an ever-growing list of third-party providers to ensure getting started is quick and easy, by providing default keys to...
Read more >@typechain/ethers-v5 - npm
TypeChain target for ethers-v5. Latest version: 10.2.0, last published: 13 days ago. Start using @typechain/ethers-v5 in your project by ...
Read more >Building a DApp with Ethers.js - LogRocket Blog
Ethers.js is a JavaScript library allowing developers to easily interact with the Ethereum blockchain and its ecosystem. Installation. Ethers.js ...
Read more >@ethersproject/properties | Yarn - Package Manager
ethers /v5.7.0 (2022-08-18 14:43) · Update PocketProvider to newer URL format. · Add new ENS normalization specification for wider UTF-8 support. · Added...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the bug! We had a clash with our
BaseModule.request
method. It so happens that EIP1193 has “stabilized” around a promise-basedrequest
method. Thankfully, our interface already matched the EIP1193 proposal before that change was even written. We were not doing our regular check on thepayload.id
parameter from that method however!I’ll have a patch released for you tomorrow!
Nice! Thanks for raising an issue. We will try to prioritize this soon, but considering Ethers V5 is beta software and we have other immediate priorities for improving Magic, it may not happen right away. We would also welcome a PR if you (or anyone else) is able to isolate the root cause! I would start my investigation here:
https://github.com/MagicHQ/magic-js/blob/797610986f3fc1d51a991a18cdaeaee132a3abd7/src/modules/rpc-provider/index.ts#L26
I’ll also ping our resident
ethers-js
expert and see if they have any ideas!