Events with truffle and ethereumjs-testrpc

SLSD123SLSD123 Member Posts: 3
I'm trying to write a simple code to record the time that someone clicks a button and then retrieve a log of all the times they've clicked the button. I am trying to use an event so that I can quickly look up all the times a particular user clicked the button.
contract TimeCard {
mapping (address => uint) public LogIn;

event CheckIn(uint _time); // so you can log the event

function TimeCard() {
LogIn[msg.sender] = 0;
}
function SignIn() public returns (uint) {
var _epoch = now;
LogIn[msg.sender] = _epoch;
CheckIn(_epoch);
return LogIn[msg.sender];
}
function ShowIn() public returns (uint){
return LogIn[msg.sender];
}
}
I then have the following code in javascript:

var accounts;
var Employee_ID;
window.onload = function() {
        var time_card = TimeCard.at(TimeCard.deployed_address);
        checkLastLog();
web3.eth.getAccounts(function(err, accs) {
                accounts = accs;
                Employee_ID = accounts[0];
                checkLastLog();
        });
}
function ListenEvents() {
        var time_card = TimeCard.at(TimeCard.deployed_address);
        var MyEvent = time_card.CheckIn();
        MyEvent.watch( function(error, result) {
                if (!error) {
                        console.log(result);
                } else {
                        console.log( error);
                }
        });
}
// Clock in
function ClockIn() {
        var time_card = TimeCard.at(TimeCard.deployed_address);
        time_card.SignIn({from: Employee_ID});
        checkLastLog();
        ListenEvents();
}
// Check Values
function checkLastLog() {
        var time_card = TimeCard.at(TimeCard.deployed_address);

        time_card.ShowIn.call().then( function(value) {
                var login_element = document.getElementById("lastLogIn");
                login_element.innerHTML = new Date(value.valueOf()*1000);
        });
}
I get an error saying:

Error: Method not found
at Object.e.exports.InvalidResponse (http://localhost:8080/app.js:4891:27099)
at http://localhost:8080/app.js:4892:23237
at XMLHttpRequest.n.onreadystatechange (http://localhost:8080/app.js:4892:7117)

at the line where I have the function call to ListenEvents(). Any help would be appreciated!
Sign In or Register to comment.