# Listening to the Transfer event ERC721 token

**URL:** <https://forum.openzeppelin.com/t/listening-to-the-transfer-event-erc721-token/829>\
**Category:** Contracts\
**Tags:** erc721\
**Created:** [June 11, 2019, 6:28am UTC](https://forum.openzeppelin.com/t/listening-to-the-transfer-event-erc721-token/829 "2019-06-11T06:28:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/sanjay/32/838_2.png) [@Sanjay](https://forum.openzeppelin.com/u/Sanjay)\
**Post date:** [June 11, 2019, 6:28am UTC](https://forum.openzeppelin.com/t/listening-to-the-transfer-event-erc721-token/829/1 "2019-06-11T06:28:28Z")

</div>

I have a contract that inherits `ERC721Mintable, Ownable`. The mint function in my contract calls the inherited `_mint(msg.sender, _tokenId)`. My understanding is that to get the token Id of the created token I have to listen to the Transfer event emited when the token is minted.  
Q1. Is this the correct way? Is there any other way?

I tried listening to the transfer event like this:

```
let instance = await MyToken.deployed();
const event = instance.allEvents();

  event
.on("data", data => {
  console.log(data);
})
.on("error", console.error);
await instance.mint(args);

```

However no events are being fired and nothing is being logged in the console  
Can you help me and point me in the right direction?

---

<div class="post-metadata">

**Author:** ![Sanjay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/sanjay/32/838_2.png) [@Sanjay](https://forum.openzeppelin.com/u/Sanjay)\
**Post date:** [June 11, 2019, 7:36am UTC](https://forum.openzeppelin.com/t/listening-to-the-transfer-event-erc721-token/829/2 "2019-06-11T07:36:19Z")

</div>

Got the solution. It was kind of a regression from my side. I was using a http provider. It does not support events

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [June 11, 2019, 8:14am UTC](https://forum.openzeppelin.com/t/listening-to-the-transfer-event-erc721-token/829/3 "2019-06-11T08:14:59Z")

</div>

Hi @sanjay well done on solving your own issue. I have been caught by that previously.

For your testing, you can use [openzeppelin-test-helpers expectEvent](https://github.com/OpenZeppelin/openzeppelin-test-helpers/blob/master/README.md#expectevent)

For an example test, see ERC721.test.js:

> <https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/test/token/ERC721/ERC721.test.js>

---

<div class="post-metadata">

**Author:** ![martriay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/martriay/32/20_2.png) [@martriay](https://forum.openzeppelin.com/u/martriay)\
**Post date:** [June 11, 2019, 7:27pm UTC](https://forum.openzeppelin.com/t/listening-to-the-transfer-event-erc721-token/829/4 "2019-06-11T19:27:20Z")

</div>

Moved to from #openzeppelin to #support:openzeppelin

---

<div class="post-metadata">

**Author:** ![Sanjay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/sanjay/32/838_2.png) [@Sanjay](https://forum.openzeppelin.com/u/Sanjay)\
**Post date:** [June 18, 2019, 11:33am UTC](https://forum.openzeppelin.com/t/listening-to-the-transfer-event-erc721-token/829/5 "2019-06-18T11:33:08Z")

</div>

Thank you so much. I was writing my tests so far myself. I did not know there were test helpers. I will start using them.
