0

set up

node.js + web3.js (0.20.6 version) + and using infura for the httpProvider

I've figured out and successfully sent erc20 tokens using the web3.js, (after a lot of googling... complete noobie here...)

and i'm now trying to figure out how to get the the token transaction history of a specific address.

i get the idea that i need to watch the events, which for token transactions, would be "Transfer" event.

so i'm following the Javascript-API for "contract events" https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-events

and below is the code i'm running (or at least trying to)

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/MYINFURATOKEN'));

var myaddress = "0x482d42bc7a5dd62f3fae88c3b4cde29a333cf913";

var contractAddress = "0x31a86307bfe81780a47fe98c192004ccdce8fcc0";

var abi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"enableTokenTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"burn","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"TransferAllowed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"frozenAccount","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"disableTokenTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"target","type":"address"},{"name":"freeze","type":"bool"}],"name":"freezeAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"initialSupply","type":"uint256"},{"name":"tokenName","type":"string"},{"name":"tokenSymbol","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"target","type":"address"},{"indexed":false,"name":"frozen","type":"bool"}],"name":"FrozenFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"","type":"bool"}],"name":"TransferEnabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"","type":"bool"}],"name":"TransferDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Burn","type":"event"}];

var myContractInstance = web3.eth.contract(abi).at(contractAddress);

var event = myContractInstance.Transfer({_from: myaddress}, {fromBlock:0, toBlock: 'latest'});

event.watch(function(error, result){
  if (!error)
    console.log(result);
});  

and that returns

Filter {
  requestManager: 
   RequestManager {
     provider: 
      HttpProvider {
        host: 'https://rinkeby.infura.io/MYINFURATOKEN',
        timeout: 0,
        user: undefined,
        password: undefined,
        headers: undefined },
     polls: {},
     timeout: null },
  options: 
   { topics: 
      [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
        null,
        null ],
     from: undefined,
     to: undefined,
     address: '0x31a86307bfe81780a47fe98c192004ccdce8fcc0',
     fromBlock: '0x0',
     toBlock: 'latest' },
  implementation: 
   { newFilter: { [Function: send] request: [Function: bound ], call: [Function: newFilterCall] },
     uninstallFilter: { [Function: send] request: [Function: bound ], call: 'eth_uninstallFilter' },
     getLogs: { [Function: send] request: [Function: bound ], call: 'eth_getFilterLogs' },
     poll: { [Function: send] request: [Function: bound ], call: 'eth_getFilterChanges' } },
  filterId: null,
  callbacks: [ [Function] ],
  getLogsCallbacks: [],
  pollFilters: [],
  formatter: [Function: bound ] }

which i'm pretty sure isn't the token transaction history... or is there a step that i'm missing?

how would i go from here?

Thank you in advance. Justin.

0

What you want is past events i believe.

  • well "getPastEvents" is only for the web3 1.0.0, which is in beta... I would rather use the stable version which is the 0.20.6 right now, and does not offer "getPastEvents" – Justin Kwon Jul 12 '18 at 4:42
0

I'm doing the same thing as you here.. This does show you the token transactions history, the thing is, it doesn't show you the history of a token transaction of a specific address.

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.