2
votes

To deploy a contract on my local set up I use truffle. The development network is running by Ganache. Also sending data on to the network from app A is no problem (using truffle/truffle-contract packages). I start this app in the same working directory as I compile and migrate the contracts

However, when I have another app connected to this network and attempt to retrieve data I run into issues. This does not use anything of truffle, only web3js.

I retrieve data as follows:

let contractInstance = new web3.eth.Contract(abi, result.contractHashes)
if (!contractInstance) handleError('Could not find contract instance... Shutting down')

for (let i in result) {
  let internalId = result[i]._id

  contractInstance.methods.getStartDate(internalId).call(function(error, result) {
    if (error) handleFatalError(error, mongoClient) // This error is triggered

    console.log(result)
  })
}

This always returns me:

Error: This contract object doesn't have address set yet, please set an address first.

From 48609913 I understand this occurs when you forget the mentioned step as described, however, I am not creating a new contract, I am simply referencing to a countract already existing in the network. It does not make sense to me if I reference to a contract by its address it does not know the contract address? Based on this article I tried to use the step missing (trail and error) following web3 options address, but same error message.

Also using

call().then(....)

or

call({ from: result.contractHashes }, function(error, result) {....})

did not work. I am pretty clueless and can not make sense of the reasoning of the issue. I hope someone with more experience among you people can.

2
What version of web3.js are you using, and what's the value of result.contractHashes? - user94559
It's an oddly named variable for what should be the address of the contract. - user94559
Hi smarx, Thank you for your time. I have version 1.0.0-beta.34. Also I agree about the naming, should be contractAddress, have to change it in another project. - Crittje
And, what's its value? Have you logged it? (My guess would be that it's empty.) - user94559
Smarx, thank you! So i had logged "result" and saw a contractHashes value. However, I did not see it actually had to be result[0].contractHashes. A bit silly, but thanks for the suggestion to look more specifically. - Crittje

2 Answers

0
votes

Check if you are importing the correct ABI file. I had come across the similar issue as I was pointing to an outdated ABI file. After I point out to the right one, the error has gone.

0
votes

First Check provide address is correct or first deploy the contract and then try to access it.because thecontractInstance.options.address = null.