I use truffle to deploy contract to ganache network. I like to use the json file generated by the truffle in the DApp rather writing messy ABI into it. I tried the below piece of code and it gives error.

var fs = require('fs');
var publish_service_abi = JSON.parse(fs.readFileSync('./PublishService_abi.json', 'utf8'));
console.log(publish_service_abi); //prints the contents of the abi
var PublishServiceContractAddress = "0x0da136781e562e28fb1c0b3efc8ce9d8b4e226f2";
PublishServiceContract = await new web3.eth.Contract(publish_service_abi,PublishServiceContractAddress);

Here is the error that I get when I run the application.

Error: You must provide the json interface of the contract when instantiating a contract object. at Contract (/home/ltu/Ganache/node3/node_modules/web3-eth-contract/src/index.js:70:15) at new Contract (/home/ltu/Ganache/node3/node_modules/web3-eth/src/index.js:147:22) at initweb3 (/home/ltu/Ganache/node3/app.js:32:34)

Any help please.

2 Answers 2


So if I understood correctly the file PublishService_abi.json is the output of truffle in the build folder - right?

If yes then this file contains more than just the abi - so to fix your problem simply change your last line of code to:

PublishServiceContract = await new web3.eth.Contract(publish_service_abi.abi,PublishServiceContractAddress);

The file generated by truffle doesn't contains only the ABI but more information. In your case you need to pass publish_service_abi.abi to your contract in order to make it work.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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