0

I am following a tutorial (hosted by dappuniversity) on youtube regarding DApps using IPFS. I have done exactly everything as mentioned in the tutorial but i get this errors:

GET https://ipfs.io/ipfs/ 400 () ipfs.io/:1 

App.js:87 Uncaught TypeError: Cannot read property 'set' of undefined
    at App.js:87
    at f (once.js:25)
    at ConcatStream (add.js:42)
    at ConcatStream.<anonymous> (index.js:37)
    at ConcatStream.EventEmitter.emit (events.js:96)
    at finishMaybe (_stream_writable.js:630)
    at endWritable (_stream_writable.js:638)
    at ConcatStream.Writable.end (_stream_writable.js:594)
    at Duplex.onend (_stream_readable.js:577)
    at Duplex.g (events.js:165)

I use MetaMask and it is linked to Ganache.

I installed IPFS and compiled and migrated the contracted using.

  • npm install ipfs --save
  • npm install --save ipfs-api
  • truffle compile
  • truffle migrate --reset

ScreenShot from my Ganache Here is the smart contract

pragma solidity 0.4.24;

contract SimpleStorage {
  string ipfsHash;

  function set(string x) public {
    ipfsHash = x;
  }

  function get() public view returns (string) {
    return ipfsHash;
  }
}

Main code on github App.js

0

Firstly, you really should add a catch clause on this promise:

// Get accounts.
this.state.web3.eth.getAccounts((error, accounts) => {
  simpleStorage.deployed().then((instance) => {
    this.simpleStorageInstance = instance
    this.setState({ account: accounts[0] })
    // Get the value from the contract to prove it worked.
    return this.simpleStorageInstance.get.call(accounts[0])
  }).then((ipfsHash) => {
    // Update state with the result.
    return this.setState({ ipfsHash })
  })
})

That is:

.catch(() => {
  console.log('Error deploying contract.')
})

Then, you receive the Cannot read property 'set' of undefined error at line 87 because of this specific object:

this.simpleStorageInstance

As you only manipulate the object in only one function other than the call on line 87, there are two possible explanations:

  1. The contract is not deployed at all, due to some systemic bug
  2. There is a delay and you somehow call onSubmit before the contract is deployed

In any scenario, double check the promise above. Logging the execution time might be helpful.

0

Paul's point of catching potential errors when you getAccounts is important.

Is the SimpleStorageContract located at the path '../build/contracts/SimpleStorage.json' in line 1?

I'm a bit of a React noob, but shouldn't you instantiate simpleStorageInstance at the top?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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