Get value from web3.eth.subscribe


I’m using infura to get all the tx of a smart contract, and I’m able to get: address,blockHash,blockNumber,data,logIndex,transactionHash and topics but how to get the _value of the tx (how many tokens were sent)?
and also what’s the first value inside topics? I’ve noticed its the same for every tx

Thanks for your help

Hello @damland, the first value inside topics is the function signature, more detail [here].(

Is this for erc20 tokens or Ether? For Ether, you can make an additional call with getTransaction to get the value transferred. For other tokens, it’s probably encoded in the the data field. See here

For Ether I need to make a getTransaction call for each tx?
Using web3.eth.getTransaction for each tx found, it will make too many infura calls, is there a workaround?

Can you copy paste the full output from your web3.eth.subscribe call? And the code snippet where you call it?

var subscription = web3house.eth.subscribe("logs", {
        fromBlock: '0x0',
        toBlock: 'latest',
        address: '0x6AC4C15dE98A3363E0113fd95cc4Ac4D8d39b563'
    .on("connected", function (subscriptionId) {
        console.log("subscriptionId:" + subscriptionId);
    .on("data", function (log) {
    .on("changed", function (log) {
    .on("error", function (error) {
        console.log("error:" + error);

and I get all the tx, like this:
This is using an erc20 token contract, I haven’t created the contract to use Ether yet, but I think the output will be very similar

Hey @damland, here’s the etherscan page with the Event Logs for that transaction.

You can see that the data is the hex encoded amount of the value transferred, so you’ll need to do a hex to decimal conversion and you’ll have the value.