I want to connect to my smart contract in a Truffle project and get some information from it. The smart contract's name is "TEST". The follow is my app.js code that should communicate with my smart contract:
var Web3=require("web3");
var web3= new Web3('ws://localhost:8545');
web3.eth.getAccounts().then(console.log);
let request=new XMLHttpRequest();
request.open("GET","E:\Emrooz\build\contracts\TEST.json");
request.send(null);
var jsonFile=JSON.parse(request.responseText);
var myContract=new
web3.eth.Contract(jsonFile,"0xC8129A44979263D578A8BD52d403d6537820e969",{
account:"0xeB2a9E0338616e35B5e844Bd38924C79D99d7346", balance:"99.98990494"});
var acc=myContract.defaultAccount;
console.log(acc.toString());
Here, "Emrooz" is name of file of Truffle project. But when i complie app.js with Nodejs the following error occurrs:
Even, i added var XMLHttpRequest=require('xmlhttprequest').XMLHttpRequest;
to the code but that error occurrs again. Whats the problem? What should i do?