I have deployed the following smart contract:
pragma solidity ^0.4.24;
contract Logistics{
address public owner = msg.sender;
mapping(address => string) public notes;
function sign(string note) public {
require(msg.sender == owner);
notes[owner] = note;
}
function transferOwnership(address newOwner) public {
require(msg.sender == owner);
owner = newOwner;
}
}
And I have written a Javascript to interact with the member functions of the smart contract.
$(document).ready(function() {///////////////////////////
let setUp = new Promise(function(resolve, reject){
if (typeof web3 !== 'undefined') {
console.log('Web3 Detected! ' + web3.currentProvider.constructor.name)
window.web3 = new Web3(web3.currentProvider);
console.log("Web3 initialized!");
resolve('done');
}
else {
console.log('No Web3 Detected... using HTTP Provider')
window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
console.log("Web3 initialized!");
resolve('done');
}
});
setUp.then(function(){ //After setup above^
web3.eth.defaultAccount = web3.eth.accounts[0]; //current metamask account
console.log("The defaultAccount is: " + web3.eth.defaultAccount);
var contractABI = web3.eth.contract([
{
"constant": false,
"inputs": [
{
"name": "note",
"type": "string"
}
],
"name": "sign",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "notes",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]);
var Note = contractABI.at(0xea449D80E775607612Cc6d5ae9232EA10e417Ec1);
$('#viewButton').click(function(){
if ($('#viewInput').val()){ //if text input is populated
Note.notes("0xf35f06208aCcaCF3FaF678df88A76142b923408e", function(err, res){
if(!err){
alert(res);
} else{
console.log("Error fetching information from given address");
}
});
}
});
}); //initial load promises 'then'
});/////////////////////////////////////////////////////
But its not working. Any idea how can I make this work?