Following is a very simple contract which implements deposit and withdraw functions. I have defined two events :

  1. deposited(address from, string msg)
  2. withDrawn(address from, string msg)

The contract is as follows:

pragma solidity ^0.4.4;
contract Bank{
uint balance;
address owner;

event deposited(address from, string msg);
event withDrawn(address from, string msg);

function deposit(uint amount){
    balance = balance + amount;
    deposited(msg.sender, "Amount has been deposited successfully");

function withDraw(uint amount){
    if(amount >= balance){
        balance = balance - amount;
        withDrawn(msg.sender, "Amount has been withdrawn successfully");

function getBalance()constant returns (uint){
    return balance;


Now, when i run this contract from command prompt using its compiled code, the events are not shown. How should i output them in nodeJS.

  • It is a good practice that accepting the answer as correct if it helped you resolved the issue. That is the whole point of SE none of the answers for your questions are marked as correct. FYI, if youre not aware of it.
    – niksmac
    Dec 23, 2016 at 2:53

1 Answer 1


You can use events like filters and they have the same methods, but you pass different objects to create the event filter.


Object - Indexed return values you want to filter the logs by, e.g. {'valueA': 1, 'valueB': [myFirstAddress, mySecondAddress]}.
Object - Additional filter options, see filters parameter 1 for more.

var event = myContractInstance.MyEvent({valueA: 23} [, additionalFilterObject])

// watch for changes
event.watch(function(error, result){
  if (!error)

// Or pass a callback to start watching immediately
var event = myContractInstance.MyEvent([{valueA: 23}] [, additionalFilterObject] , function(error, result){
  if (!error)

Read Contract Events

Your Answer

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

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