0

When I launch the app with with react.. this error occur when my exchange contract is loaded.. Here is the code i wrote to talk to the blockchain:

export const loadBalances = async (dispatch, web3, exchange, token, account) => {
  const etherBalance = await web3.eth.getBalance(account)
  dispatch(etherBalanceLoaded(etherBalance))

  const tokenBalance = await token.methods.balanceOf(account).call()
  dispatch(tokenBalanceLoaded(tokenBalance))

  const exchangeEtherBalance = await exchange.methods.balanceOf(ETHER_ADDRESS, account).call()
  dispatch(exchangeEtherBalanceLoaded(exchangeEtherBalance))

  const exchangeTokenBalance = await exchange.methods.balanceOf(token.options.address, account).call()
  dispatch(exchangeTokenBalanceLoaded(exchangeTokenBalance))

  dispatch(balancesLoaded())
}

web3 v1.0.0 beta46 Truffle v5.0.5 (core: 5.0.5) Solidity v0.5.0 (solc-js) Node v9.10.0

Here is the error when i use the debugger enter image description here

Update: The error i get when i update to web3 v1.2.1 enter image description here

16
  • Your call stack is incomplete, but it appears to be a problem with loadBalances function and not loadExchange.
    – Ismael
    Sep 12, 2019 at 1:53
  • Hi Ismael.. This error occur after the loadExchange function.. This is the only function that suck on the "interaction.js" script.. (i'm using Redux) Sep 12, 2019 at 2:32
  • The call stack is incomplete so take what I say with caution but if you look at the bottom there is a loadBalances at interactions.js:130, and everything above it seems related to balances. Without debugging the source code is hard to say anything else.
    – Ismael
    Sep 12, 2019 at 3:17
  • Hi Ismael. I saw the loadBalances at interactions.js:130 But now how can i complete the call stack?? Because before that there was not this problem at this level I do not know why it started to make bugs.. And i'm a beginner in the dApp development.. Sep 12, 2019 at 13:32
  • You can try to set a breakpoint there and examine the parameters values. Add more debug code around there is no magic you have to debug it like any other webapp.
    – Ismael
    Sep 12, 2019 at 14:30

1 Answer 1

2

You declared you function as async but never used the async/await pattern. I added the await at the correct position for you.

Try this:

export const loadExchange = async (web3, networkId, dispatch) => {
  try {
    const exchange = await web3.eth.Contract(Exchange.abi, Exchange.networks[networkId].address)
    dispatch(await exchangeLoaded(exchange))
    return exchange
  } catch (error) {
    console.log('Contract not deployed to the current network. Please select another network with Metamask.')
    return null
  }
}
7
  • Hi Niklas the result still the same with the keyword "await".. Sep 11, 2019 at 19:54
  • Try adding in the second await as well. (I'm not certain if it works that way)
    – cqx
    Sep 11, 2019 at 20:02
  • Same thing.. I added the second await on the dispatch function.. Sep 11, 2019 at 20:06
  • Please provide the output of Exchange.networks[networkId].address I think its empty
    – cqx
    Sep 11, 2019 at 20:19
  • You can see the address objet on the screenshot.. Sep 11, 2019 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.