2

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.

Crittje
  • 101
  • 1
  • 3
  • 11
  • What version of web3.js are you using, and what's the value of `result.contractHashes`? – user94559 Jul 11 '18 at 18:54
  • It's an oddly named variable for what should be the address of the contract. – user94559 Jul 11 '18 at 18:55
  • 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 Jul 12 '18 at 08:00
  • And, what's its value? Have you logged it? (My guess would be that it's empty.) – user94559 Jul 12 '18 at 08:02
  • 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 Jul 13 '18 at 10:04
  • Any update on this? – lemur Nov 01 '18 at 12:58
  • Hi mtsfaria, yes, the issue was that it returns an array. So I had to call result[0].contractHashes instead of result.contractHashes – Crittje Nov 01 '18 at 16:19

2 Answers2

1

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

0

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.

babs
  • 141
  • 1
  • 3