Im trying to interact with my smart contract using web3js.

when i run js file using node instance i.e. node myfile.js

Im getting error like

undefined 1

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.<anonymous> (~/Documents/Project/miner1/requestor.js:234:19)

line 234 code is var accAbi = JSON.parse(web3.utils.hexToAscii(accAbiBytes));

Here is my code from line number 228

var methodName = "Method1";
var register = web3.eth.Contract(regAbi, regAddr);
var accAddr = register.methods.getContractAddr(methodName);
var accAbiBytes = web3.utils.bytesToHex(register.methods.getContractAbi(methodName));
//var accAbiBytes_new = web3.utils.utf8ToHex(accAbiBytes);
var accAbi = JSON.parse(web3.utils.hexToAscii(accAbiBytes));

can anybody help me. I tried some solutions in stackoverflow but nothing worked.

  • To begin with, add await before register.methods, and put everything inside an async function. – goodvibration May 8 '19 at 7:22
  • @goodvibration Im new to this stuff and javascript also. Can you send me updated code . Thanks in adavance – Satish Ganta May 8 '19 at 8:06
  • 1
    No, and it won't get you much farther anyway, because you'll just stumble across another syntax problem. You need to learn the language syntax and understand how to resolve simple problems such as this one. For example, the error here tells you that the input to JSON.parse is wrong. You should have therefore checked what input you are passing to this function and investigate how this input is different from what the function expects. – goodvibration May 8 '19 at 8:16

Your Answer

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

Browse other questions tagged or ask your own question.