Get value from web3.eth.subscribe

Hello,

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].(https://forum.ethereum.org/discussion/16377/web3-subscribe-topics)

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) {
        console.log(JSON.stringify(log));
    })
    .on("changed", function (log) {
        console.log(JSON.stringify(log));
    })
    .on("error", function (error) {
        console.log("error:" + error);
    });

and I get all the tx, like this:
{“address”:“0x6AC4C15dE98A3363E0113fd95cc4Ac4D8d39b563”,“blockHash”:“0x160e4b2a0ca2a71434376e27cdeb73d84e617ab154aea9a5c5188984726dad6b”,“blockNumber”:7622409,“data”:“0x00000000000000000000000000000000000000000000000000000000001e8480”,“logIndex”:3,“removed”:false,“topics”:[“0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef”,“0x000000000000000000000000d1d4c23e18181a131237f4235b5c356a2b4746f8”,“0x000000000000000000000000ad5d3fba85e16b044094788379507cbd8c8cdbfb”],“transactionHash”:“0x6953ee96bb018cfba85ce5e5d6a226f991d4d0485ad250158b317cab91b98c05”,“transactionIndex”:18,“id”:“log_5eb0cbe0”}
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. https://ropsten.etherscan.io/tx/0x6953ee96bb018cfba85ce5e5d6a226f991d4d0485ad250158b317cab91b98c05#eventlog

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.