Skip to content
Advertisement

Uncaught (in promise) Error: invalid address

how to fix this error when i call a smart contract function?

Uncaught (in promise) Error: invalid address (argument="address", value={"from":"0xaD1D30B476C195C23ef4CC9b7A3c53E7423B7690"}, code=INVALID_ARGUMENT, version=address/5.0.5) (argument="index", value={"from":"0xaD1D30B476C195C23ef4CC9b7A3c53E7423B7690"}, code=INVALID_ARGUMENT, version=abi/5.0.7)

it’s my code:

enter: async function() {
    App.contracts["MyContract"].deployed().then(async(instance) =>{
      var a = web3.eth.getAccounts();
      let ticketsForPlayers  = await instance.getTicketsForPlayers({from: App.account});
      console.log(ticketsForPlayers);
    });
  }

Advertisement

Answer

The Problem

The error shows that you didn’t set the address property correctly, it’s may be the issue with your solidity implementation and it’s not related to javascript snippet, as mentioned in the comments, you can ask about it on related sites, but there are some points with the above snippet that may help you. you are mixing two different implementations in enter method to handle a promise which is clearly incorrect and leads to the issues.

The Points

use async/await with try/catch block. more on MDN documentation:

enter: async function () {
  try {
    const instance = await App.contracts["MyContract"].deployed()
    
    const properNameForVariable = web3.eth.getAccounts();

    const ticketsForPlayers = await instance.getTicketsForPlayers({from: App.account})

    console.log(ticketsForPlayers)
  } catch (error) {
    // do a proper action on failure cases
  }
}

Now, if there are errors in your async actions, it catches by catch block, you may also use console.error(error) or console.warn(error) in the catch block to see the exception and stack traces.

Note: using this approach with try/catch will ensure the application continues to work even after exceptions and errors.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement