Skip to content
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

Can't catch Unhandled Rejection (Error): resolver or addr is not configured for ENS name (argument="name", value="", code=INVALID_ARGUMENT, version=contracts/5.0.8) #1234

Closed
0xmikko opened this issue Jan 12, 2021 · 51 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@0xmikko
Copy link

0xmikko commented Jan 12, 2021

Hi! I run this code in browser, and can't catch promise rejection.
Important: I added await before getContract,however in typings you return Contract, not Promise but the code throw promise rejection!

Code:
let vault;
try {
vault = (await ethers.ContractFactory.getContract(
CONTRACT_ADDRESS,
vaultJson.abi,
signer
) as unknown) as Vault;
} catch (e) {
console.log("Error getting contract");
return;
}

Expected behavior:
Rejection in getContract would be caught in try-catch block

Real outcome:
Unhandled Rejection (Error): resolver or addr is not configured for ENS name (argument="name", value="", code=INVALID_ARGUMENT, version=contracts/5.0.8)

@ricmoo
Copy link
Member

ricmoo commented Jan 12, 2021

Thanks! I’ll look into this shortly...

@ricmoo ricmoo added investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Jan 12, 2021
@0xmikko
Copy link
Author

0xmikko commented Jan 12, 2021

Typings for ethers:
static getContract(address: string, contractInterface: ContractInterface, signer?: Signer): Contract;

@0xmikko
Copy link
Author

0xmikko commented Jan 12, 2021

Code:

      try {
        vault = (await ethers.ContractFactory.getContract(
          CONTRACT_ADDRESS,
          vaultJson.abi,
          signer
        ) as unknown) as Vault;
      } catch (e) {
        console.log("Error getting contract");
        return;
      }

@0xmikko
Copy link
Author

0xmikko commented Jan 12, 2021

To clarify the issue, I test this code especially for throwing error, passing CONTRACT_ADDRESS=undefined to check behavior in my app when error occurs. I expect that the error should be catched.

@ricmoo
Copy link
Member

ricmoo commented Jan 12, 2021

I agree. Errors should be recoverable using normal JavaScript conventions. :)

@ricmoo
Copy link
Member

ricmoo commented Jan 12, 2021

(you shouldn’t need to await)

@0xmikko
Copy link
Author

0xmikko commented Jan 13, 2021

Okay, I added await after getting an error of unhandled promise - which I perceived that there are some async code there. Unfortunately, I got the same behavior without await also.

@ricmoo
Copy link
Member

ricmoo commented Jan 13, 2021

Yeah. The await will have no effect. I need to swallow the error. It won’t throw an error in general though, since that resolution of ENS name to address is async.

In your case though, I can add a condition that throws if address is not a string, so you will get a sync error for you. But in general it won’t fail for users who pass in an invalid string until they try calling a method on the Contract.

I’ll check into these changes tomorrow and kinda trace through some behaviour to make sure it all still makes sense. :)

@0xmikko
Copy link
Author

0xmikko commented Jan 13, 2021

The same behavior with empty string also:

 let vault;
      try {
        vault = (ethers.ContractFactory.getContract(
          CONTRACT_ADDRESS || "",
          vaultJson.abi,
          signer
        ) as unknown) as Vault;
      } catch (e) {
        console.log("Error getting contract");
        return;
      }

This is stack trace:

    makeError index.ts:205
    throwError index.ts:217
    throwArgumentError index.ts:221
    resolveName index.ts:117
    fulfilled 0.chunk.js:5105
    promise callback*step 0.chunk.js:5120
    fulfilled 0.chunk.js:5105
    promise callback*step 0.chunk.js:5120
    node_modules 0.chunk.js:5123
    node_modules 0.chunk.js:5102
    resolveName 0.chunk.js:5153
    Contract index.ts:663
    getContract index.ts:1210

@0xmikko
Copy link
Author

0xmikko commented Jan 16, 2021

Any update?

@ricmoo ricmoo added bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels Feb 12, 2021
@ricmoo
Copy link
Member

ricmoo commented Feb 13, 2021

This should be fixed in 5.0.31. Try it out and let me know! :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Feb 13, 2021
@ricmoo
Copy link
Member

ricmoo commented Feb 16, 2021

I think this is fixed, so I'll close this now. If not, please re-open.

Thanks! :)

@ricmoo ricmoo closed this as completed Feb 16, 2021
@jadbox
Copy link

jadbox commented Feb 20, 2021

seems like it might be still broken for me @ricmoo

@miguelmota
Copy link

miguelmota commented Apr 16, 2021

Experiencing same issue; error is uncatchable

    invalid ENS name (argument="name", value=undefined, code=INVALID_ARGUMENT, version=providers/5.1.0)

      at Logger.Object.<anonymous>.Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:205:28)
      at Logger.Object.<anonymous>.Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:217:20)
      at Logger.Object.<anonymous>.Logger.throwArgumentError (node_modules/@ethersproject/logger/src.ts/index.ts:221:21)
      at StaticJsonRpcProvider.<anonymous> (node_modules/@ethersproject/providers/src.ts/base-provider.ts:1440:14)
      at step (node_modules/@ethersproject/providers/lib/base-provider.js:48:23)
      at Object.next (node_modules/@ethersproject/providers/lib/base-provider.js:29:53)
      at fulfilled (node_modules/@ethersproject/providers/lib/base-provider.js:20:58)

Using ethers ^5.1.0

EDIT: Nevermind! My issue was unrelated. It's working as expected.

@jeromevvb
Copy link

@miguelmota How did you fix it? I have the same error

@miguelmota
Copy link

@jeromevvb the issue for me was I had a nullish address which of course can't be resolved. Check your input values

@elie222
Copy link

elie222 commented Jan 11, 2022

We were getting this error for contract(''). Obviously wouldn't work but took some time to track down in our code.

Hi Elie222, Just curious as to where you found the error in your code for this?

We saw the same error as posted at the top of this thread. In short don't do contract(''), do: contract('0x123abc')

@aspiers
Copy link

aspiers commented Jan 23, 2022

@ricmoo It seems to me like this needs to be reopened, as apparently there are many people struggling to track down why an ethers function is being called with an empty or undefined address. I have hit this many times myself, where the stack trace does not give any indication of which code triggered the ethers API call causing the unhandled rejection.

@ricmoo
Copy link
Member

ricmoo commented Jan 23, 2022

I would rather focus on getting v6 out the door though. The error is correct, that somewhere an address is expected, that "undefined" is being passed in. From the issues, so far it seems quite often this comes from people using unset environment variables, mis-typing the property on an object or passing in values from an optional function argument. This seems little outside the scope of ethers to attempt to detect.

One problem with making this easier to track down, is that this can occur at many stages in a heavily async process, such as in a nested struct, which currently allows nested async values, so it isn't a simple matter to make this work in general. In v6, a lot of the async options are going away (i.e. methods no longer accept Deferrables, for many values), so I would prefer getting that out.

If you (or anyone else) can find a simple way to detect and display the stack in a meaningful sense though, I am all ears. But no easy, safe and portable solution comes to mind.

Does that make sense?

@aspiers
Copy link

aspiers commented Jan 24, 2022

Thanks a lot @ricmoo for the great response. Yes, if there's no easy way of getting better stack traces then I guess we can just look forward to v6.

However as a quick fix, I'm pretty confident that there should be a way to reword the existing message to make it much more helpful. The ENS reference is generally a complete wild goose chase. As you say, this error is often caused by incorrect arguments, and it's nothing to do with ENS. The error message should at least mention the most probable cause, and ideally put that front and center. I'm not saying it shouldn't mention ENS, but if that's only one relatively unlikely cause of the error, then the message should reflect the balance of probabilities.

Furthermore, it's not at all clear what argument="name" is supposed to refer to, or whether value="" means that an empty string was accidentally passed instead of an address, or something else. Currently this reads like an internal error which assumes knowledge of how ethers internals work. From the perspective of an API consumer, that makes things difficult to understand. If the message was made more friendly to your primary audience, I suspect you'd see a significant reduction in the number of issues submitted relating to this error.

Thanks again!

@dosjcq
Copy link

dosjcq commented Jan 24, 2022

Hello, I think, that I got quite same error:
Error: missing provider (argument="provider", value=undefined, code=INVALID_ARGUMENT, version=providers/5.5.0)
It happens, when metamask is not installed or disabled in Chrome.
Could you help me understand, if this is happening because of me or something else and if I can somehow handle this error. Thank you for help!

@ricmoo
Copy link
Member

ricmoo commented Jan 24, 2022

@dosjcq Looks like you are passing in window.ethereum without checking that it is defined first. You have to check if the use has Ethereum and if not act accordingly. You probably want to connect to a default provider in the event, and use that instead if there is no provided provider, so there is at least read-only access.

@dosjcq
Copy link

dosjcq commented Jan 24, 2022

@ricmoo, Thank you for your answer, I will try

@Prateeknandle
Copy link

I also got the same error, I think the issue was not assigning contract address properly there should be no space in " ", write correct address and it'll get resolved :)

@Joetoledano
Copy link

@dosjcq Looks like you are passing in window.ethereum without checking that it is defined first. You have to check if the use has Ethereum and if not act accordingly. You probably want to connect to a default provider in the event, and use that instead if there is no provided provider, so there is at least read-only access.

@dosjcq not sure if this is particularly relevant for you but something like this might help:

const provider = window && window.ethereum ? new ethers.providers.Web3Provider(window.ethereum) : new ethers.providers.JsonRpcProvider(url);

@kuabhish
Copy link

kuabhish commented Jul 9, 2022

Hello, I am receiving the same error.

Error: invalid address or ENS name

I want to run these functions from a node js code. I checked: my address is correct.

@ricmoo
Copy link
Member

ricmoo commented Jul 9, 2022

@kuabhish please include the entire error; the error indicates what was passed in. Use a console.log to make sure it is what you expect too. :)

@kuabhish
Copy link

kuabhish commented Jul 9, 2022

Screenshot 2022-07-10 at 2 18 25 AM

I initiated the provider with const provider = new ethers.providers.AlchemyProvider("maticmum", "api key")

I am using an alchemy node to hit the mumbai testnet.

@ricmoo
Copy link
Member

ricmoo commented Jul 9, 2022

@kuabhish the error says the value passed in is undefined. Make sure you are isolating the correct line, and console.log all values you are passing in. Usually this error is because an environment variable was not properly loaded (typo) or unpacking an object was missing an await or such.

@toddnagel
Copy link

I solved this issue.. turns out we were using it before the address was actually defined, so the fault was ours.. hope this helps.. a little magic with React and problem went away!

@yeso8615
Copy link

Can someone help me, I read the whole thread, and I couldn't solve the problem.

Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.6.2)

Source
pages\portal.js (89:25) @ _callee$

87 | const key = simpleCrypto.decrypt(cipherHH)
88 | const wallet = new ethers.Wallet(key, provider);

89 | const contract = new ethers.Contract(hhnft, NFT, wallet);
| ^
90 | const itemArray = [];
91 | contract._tokenIds().then(result => {
92 | for (let i = 0; i < result; i++) {

@elie222
Copy link

elie222 commented Jul 27, 2022

Can someone help me, I read the whole thread, and I couldn't solve the problem.

Error: invalid contract address or ENS name (argument="addressOrName", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.6.2)

Source pages\portal.js (89:25) @ _callee$

87 | const key = simpleCrypto.decrypt(cipherHH) 88 | const wallet = new ethers.Wallet(key, provider);

89 | const contract = new ethers.Contract(hhnft, NFT, wallet);
| ^
90 | const itemArray = [];
91 | contract._tokenIds().then(result => {
92 | for (let i = 0; i < result; i++) {

This is the problematic line.

const contract = new ethers.Contract(hhnft, NFT, wallet);

If you console log hhnft you should see that it's undefined. ethers.Contract expects a valid address as it's first argument.

@snapier494
Copy link

Error: invalid address or ENS name (argument="name", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.6.2)
at Logger.makeError (node_modules@ethersproject\logger\src.ts\index.ts:261:28)
at Logger.throwError (node_modules@ethersproject\logger\src.ts\index.ts:273:20)
at Logger.throwArgumentError (node_modules@ethersproject\logger\src.ts\index.ts:277:21)
at E:\BlockChain\hardhat-tutorial\node_modules@ethersproject\contracts\src.ts\index.ts:123:16
at step (node_modules@ethersproject\contracts\lib\index.js:48:23)
at Object.next (node_modules@ethersproject\contracts\lib\index.js:29:53)
at fulfilled (node_modules@ethersproject\contracts\lib\index.js:20:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at listOnTimeout (node:internal/timers:533:9)

@holma91
Copy link

holma91 commented Aug 20, 2022

Apparently you get this error message if you specify the contract call value in the beginning of the params, instead of in the end. When I do this:

await contract.randomPayableFunc({value: 0.1}, arg1, arg2)

I get

Error: invalid address or ENS name (argument="name", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.6.2)

But when I do

await contract.randomPayableFunc(arg1, arg2, {value: 0.1})

it works fine. Leaving this up here to help people in the future because it's easy to start looking at other things when getting this error message :)

@ricmoo
Copy link
Member

ricmoo commented Aug 20, 2022

Of course! The order of parameters passed into a method matter in JavaScript. Otherwise how would it know which parameter is what? :p

@wmlimanto
Copy link

hello! i'm trying to send a payment through metamask on a web app built with react and am still facing the same issue:

invalid address (argument="address", value=null, code=INVALID_ARGUMENT, version=address/5.7.0)

not sure what's the issue / how to resolve it? would appreciate any input! thanks

@ricmoo
Copy link
Member

ricmoo commented Oct 9, 2022

@wmlimanto it means somewhere you are passing null into a function needs an address. You are also using an ancient version of ethers. Try upgrading too, which may resolve your issue.

@wmlimanto
Copy link

@ricmoo thanks for getting back to me!

i just checked and i'm on ethers v5.7.1, which should be the latest version if i'm not mistaken?

not sure where you are referring to that i need to pass the address, if you don't mind looking at my code:

// initialize connection with metamask wallet
const startPayment = async ({ setError, setTxs, ether, addr }) => {
  try {
    // throw this error if user doesn't have a metamask wallet
    if (!window.ethereum)
      throw new Error("No crypto wallet found. Please install it.");

    // ask user for permission to connect with metamask wallet
    await window.ethereum.send("eth_requestAccounts");

    // establish connection with eth provider to send tx
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const signer = provider.getSigner();

    // validate receiving addr
    ethers.utils.getAddress(addr);
    
    // create the tx; to which addr & how much eth (converted to wei)
    const tx = await signer.sendTransaction({
      to: addr,
      value: ethers.utils.parseEther(ether)
    });
    console.log({ ether, addr });
    console.log("tx", tx);
    // add tx hash id to TxList to display tx id to user
    setTxs([tx]);
  } catch (err) {
    setError(err.message);
  }
};

thanks so much!

@ricmoo
Copy link
Member

ricmoo commented Oct 9, 2022

@wmlimanto check your stack trace, it will give you the exact line number that is the problem. My guess is that addr is null. Add a console.log to the top of your function.

@wmlimanto
Copy link

@ricmoo yup seems like you're right - console.log({ ether, addr }) is telling me that both values are null.

trying to debug this issue now, appreciate your help! hope to update on a solution soon

@nisargpatel1504
Copy link

Error: index.ts:269 Uncaught (in promise) Error: invalid address or ENS name (argument="name", value=undefined, code=INVALID_ARGUMENT, version=contracts/5.7.0)
at Logger.makeError (index.ts:269:1)
at Logger.throwError (index.ts:281:1)
at Logger.throwArgumentError (index.ts:285:1)
at index.ts:123:1
at Generator.next ()
at fulfilled (index.ts:1:1)

const CONTRACT_ADDRESS = "0x47CC05c245EaAb22834c03E57120603c845E9157"
const connectAndLoad = async () => {
    const provider = new ethers.providers.Web3Provider(window.ethereum);
      setProvider(provider);
    const contract = new ethers.Contract(CONTRACT_ADDRESS, artifact.abi,provider);
      setContract(contract); 
    const signer = await getSign(provider)
    setSigner(signer);
    
    const signerAddresses = await signer.getAddress()
    setSignerAddress(signerAddresses);

    const assetIds = await getAssestId(signerAddress,signer)
    setAssetsIds(assetIds);

    getAssets(assetIds,signer);

  }

@laespinaworld
Copy link

laespinaworld commented Nov 14, 2022

Hi there guys, i am getting the same error

index.ts:269 Uncaught (in promise) Error: resolver or addr is not configured for ENS name (argument="name", value="", code=INVALID_ARGUMENT, version=contracts/5.7.0)
at Logger.makeError (index.ts:269:28)
at Logger.throwError (index.ts:281:20)
at Logger.throwArgumentError (index.ts:285:21)
at index.ts:140:16
at Generator.next ()
at fulfilled (_version.ts:1:24

This is my code
`
import contract from './AegisWarrior.json';

export const ADDRESS = "0x1Cb0DFD5208823F08516E4Aa0CDc4b04F2d6a88c"
export const { abi: ABI } = contract

`
CONTEXT !!!

//* Set the smart contract and provider to the state
useEffect(() => {
const setSmartContractAndProvider = async () => {
const web3Modal = new Web3Modal();
const connection = await web3Modal.connect();
const newProvider = new ethers.providers.Web3Provider(connection);
const signer = newProvider.getSigner();
const newContract = new ethers.Contract(ADDRESS, ABI, signer);

  setProvider(newProvider);
  setContract(newContract);
};

setSmartContractAndProvider();

}, []);

any solutions?

@SahithShetty
Copy link

@laespinaworld I understand that you are doing NFT card game tutorial.
Even I'm facing the same error, pls tell me if it got resolved for you by this time.

Thank you so much.

@hariprasad9899
Copy link

Did anyone finally figured it out ?

@aspiers
Copy link

aspiers commented Feb 19, 2023

I recently submitted PR #3774 - while it may not help with this particular issue where the cryptic error is typically thrown while trying to resolve an empty or undefined contract address, it should help with similar mistakes where undefined is accidentally passed as one of the contract call arguments. For example, where it would previously output an error like this:

invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)

when using this PR, it will prepend the above error with something like the following:

Error: Failed to encode _myTuple as tuple(string,uint64,uint64,uint256,uint64,bool,bool,string,string,string,string): value=20180301,1519862400,1546214400,,12345,false,false,,,,

Failed to encode fieldNameStupidlyMissedFromParamsObject as uint256: value=undefined

which makes it clear exactly which parameter was set to undefined when it should have been a number.

TBH, I'm still confused why it wouldn't be easy to add a similar try / catch kind of thing around the code which attempts to resolve addresses, in order to improve the debugging in the same way that #3774 allows pinpointing of exactly which argument caused the problem. But admittedly I'm not super familiar with ethers.js internals, so maybe I'm missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests