-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid ENS name error when a signer is used instead of an address #1051
Comments
I'm getting this error too, any tips on the solution? |
It will be helpful if you can provide some more information, i.e. what ethers version are you using, what network are you on, sample code to reproduce this. I have seen this happen when passing in an invalid address and ethers treating it as an ENS name and trying to resolve the address from it. |
Example problematic code:
Yields confusing error:
Fix:
I guess extra confusing for typescript users, as the types are happy with it, only breaks at runtime. |
@ryan-snyder @Aindigo is this what you're referring to? |
I haven’t looked much into this, but there is no |
There is also no My guess is you want to call |
One of my deepest regrets 🥲 We need to come up with a better way of doing this. Originally that This problem mostly happens when users pass a Signer or Contract instead of an address. I think something that would improve it is checking if the value is a string, and only throw ENS-related errors in that case. |
This may also be extended by running some fuzzy "validation" of the string. Like, only consider it an ENS name if it has a dot. |
If I get the reports correctly, just checking |
For me, something that fixed the original error was just changing a function call token.balanceOf(user) to token.balanceOf(user.address). Not quite sure why this throws the Invalid ENS name error though but maybe this might help. |
@Legogris if you use TypeChain you WILL get compile-time error when you forget to call That being said it's extremely confusing and I feel like ethers should treat signers as addresses representing these signers in this case. Would you accept a PR fixing this? @alcuadrado proposed some ideas in the original post. I can also imagine a check something like "if parameter is an instanceOf Signer use signer.address instead. |
This has already been added to my local v6. You should actually generally call For v5, I can add a condition like that to the JavaScript side, but cannot change the signature to allow Signer and Contract since that would break any existing sub-classes. |
Great! Any ETA for the v6 release?
Yeah... I get that it's just getAddress() is async so it needs
I think adding it JS side should be good enough! I believe that we can still generate TS typings in TypeChain in the way that it accepts signers (for smartcontract calls). |
Hi there, I'm having the same error but with somewhat different code, and I'd greatly appreciate some insight about this since I've been stuck with it for a few days. My Signer-based contract instance has worked with My contract's Error
Please let me know if you want more of the error's trace, it was quite repetitive My code, simplified a bitAbout the source below:
Solidity function signature
|
Hey there, same problem as @slhodak if anyone found a solution please let me know |
What parameters are you passing in? Can you console.log them? |
Hey thanks for the quick reply ! That's totaly on me. I found out the problem 5 mins after posting (stupid bad venv ariable names hidden deep in my code...). Sorry for the inconvenience ! |
I'm still getting an error when I try to run this code. I'm new to frontend smart contract work, so this may be an obvious error, but I can't figure out what I'm doing wrong here:
I get the owner.toString() to come back as expected, but afterwards I get the 'invalid ENS name' error |
Can you console log the |
Ran into this error as well. An error message like "Invalid address" would make it much less confusing than "Invalid ENS name" |
This should be better in 5.5.0. The error thrown is more meaningful and does not mention ENS. In v6, Thanks! :) |
For anyone reading this and whose solution isn't above be aware that this error can be thrown when the contract code is too large. Look at the logs of your local node, I had |
For any one wondering why Try, |
Use this code to resolve the error in the ### console import React, { useEffect, useState } from "react"; import { contractABI, contractAddress } from "../utils/constants"; export const TransacionContext = React.createContext(); const { ethereum } = window; const getEthereumContract = () => { async function create() { console.log({ |
For Buffer Warning in the console Use This packageInstall buffer package, as correctly: npm i buffer |
Hey @ricmoo
I'm creating this issue cause I've seen lots of people confused about an ENS related error being thrown when a signer is used instead of an address. To make things worse, the signer gets
JSON.stringify
d so the error is HUGE sometimes.Have you consider treating this as a special case and throwing something like "hey, you should use an address instead of a signer"? Or maybe add a
toJSON
to the abstract signer to at least avoid those huge errors?The text was updated successfully, but these errors were encountered: