My contract pragma solidity ^0.5.0;

contract Transfereventaction {

    event Deposit(
        address indexed _from,
        bytes32 indexed _id,
        uint _value

    function deposit(bytes32 _id) public payable {
        // Events are emitted using `emit`, followed by
        // the name of the event and the arguments
        // (if any) in parentheses. Any such invocation
        // (even deeply nested) can be detected from
        // the JavaScript API by filtering for `Deposit`.
        emit Deposit(msg.sender, _id, msg.value);


Try with

const infura = "wss://ropsten.infura.io/ws";
const web3 = new Web3(new Web3.providers.WebsocketProvider(infura));

also not working

My node js code

const infura = "ws://ropsten.infura.io/v3/id";
const web3 = new Web3(new Web3.providers.WebsocketProvider(infura));
var ClientReceipt = new web3.eth.Contract(abi ,contract_address);

    fromBlock: "latest"
}, (error, event) => { console.log("Event result is "+ event); }).on('data', (event) => {
    console.log("data event"+event); // same results as the optional callback above
}).on('changed', (event) => {
    console.log("changed event" + event) // remove event from local database
.on('error', console.error);

emit is not call while token transfer to contract.

My node js code is in listen and it didn't print the console message while I send token to my contract

I need to know when the contract gets token. Pls guide me in the correct way

Pls let me know if I miss anything in the code


You listen the event from the latest block so if your event is not in the latest one you don’t have any event. Try with fromBlock: 6039496 for example.

  • Thanks for your answer. but it is not working. Function not triggered while sending the token Jul 23 '19 at 5:49
  • Did you try getPastEvents and which version of web3 do you use?
    – n1c01a5
    Jul 23 '19 at 10:11
  • No i will try and let you know Jul 23 '19 at 10:25
  • I got "ClientReceipt.events.getPastEvents is not a function" error Jul 23 '19 at 10:26
  • I want to trigger a function while my contract receive a token Jul 23 '19 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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