I want to write a simple js script. I follow many tutorial available from Youtube, forums and website but i seem that i cannot interact from the smart contract. i can interact it from remix. btw the smart contract is deployed on my private network.
Web3 = require('web3');
console.log("Hi blinkExample")
const web3 = new Web3(new Web3.providers.HttpProvider('http://192.168.100.130:8043'));
web3.eth.getAccounts()
.then(console.log);
web3.eth.defaultAccount = web3.eth.accounts[0];
var coinbase = web3.eth.coinbase;
var contractAddress = '0x6b9781fe8b355965a7ce99f58b918f711ab5fe1e';
var abi = [
{
"constant": false,
"inputs": [
{
"name": "theData",
"type": "uint256"
}
],
"name": "setData",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "data",
"type": "uint256"
}
],
"name": "blinkEvent",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "getData",
"outputs": [
{
"name": "retData",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "myData",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
var blinkContract = web3.eth.Contract(abi, contractAddress);
var data = blinkContract.getData;
console.log('value is' + data);
var event2 = blinkContract.blinkEvent(function(error, result){
if (!error){
console.log(result);
}
});
the console will show account list just fine but displays "value is undefined" then crash for the blinkEvent with typeError: blinkContract.blinkEvent is not a function. The value should be 12 which I set using remix.