ethereum-solidity-course-updated-code icon indicating copy to clipboard operation
ethereum-solidity-course-updated-code copied to clipboard

SyntaxError: Unexpected token u in JSON at position 0 (factory.js)

Open indieangler opened this issue 3 years ago • 1 comments

First off, thanks for this - really appreciate it. I've recently updated to Solidity 0.8.9 and have been struggling to refactor accordingly. I was initially having issues with compile.js and deploy.js but finally got those sorted thanks to your repo.

However, now when I start up the node server and view in browser, I'm getting a "SyntaxError: Unexpected token u in JSON at position 0" error with regards to factory.js which was a file I haven't touched recently. My factory.js looks like this:

import web3 from './web3';
import CampaignFactory from './build/CampaignFactory.json';

const instance = new web3.eth.Contract(
  JSON.parse(CampaignFactory.interface),
  'mydeployedfactoryaddress'
);

export default instance;

However, nothing loads any more. I've checked that the factory contract has successfully been deployed to that stated address (with Etherscan) on the Rinkeby network and it has - no issues there. Any idea what might be causing this? Much appreciated!

indieangler avatar Oct 19 '21 16:10 indieangler

Hi @indieangler sorry for the delay in responding, I've been meaning to finish up my update of this entire repo to Solidity 0.8 by now but have been sidetracked working on some blockchain projects. Without seeing the code for your entire Kickstart/CrowdCoin app and just looking at the snippet you've provided I would say the reason for your issue is the JSON.parse(CampaignFactory.interface) argument to web3.eth.Contract. Try replacing your snippet with the following:

import web3 from './web3';
import CampaignFactory from './build/CampaignFactory.json';

const instance = new web3.eth.Contract(
  CampaignFactory.abi,
  'mydeployedfactoryaddress'
);

export default instance;

owanhunte avatar Oct 29 '21 03:10 owanhunte

Hi @indieangler this issue is rather old now and no longer valid since there have been significant upgrades to the Next.js framework and the various libraries the Kickstart app needs to use, since this issue was opened. I'm in the process of updating this repo's version of the Kickstart app to the latest Next.js and third-party library versions, as well as ensuring the smart contracts and the Node.js compile/deploy/test scripts are all fully up-to-date. Once I've completed those updates, please be sure to test things with that future version of the repo and if you still experience any issues then, feel free to open a new issue.

For now, I'm going to close this issue.

owanhunte avatar Feb 22 '23 01:02 owanhunte