Skip to content

Commit

Permalink
Add tokentx action support to account module which allows getting a l…
Browse files Browse the repository at this point in the history
…ist of ERC20 tokes transfer events
  • Loading branch information
mazikwyry committed Jun 6, 2018
1 parent d250805 commit ec0c448
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,43 @@ module.exports = function(getRequest, apiKey) {
module, action, address, apiKey
});
return getRequest(query);
},
/**
* [BETA] Get a list of "ERC20 - Token Transfer Events" by Address
* @param {string} address - Account address
* @param {string} startblock - start looking here
* @param {string} endblock - end looking there
* @param {string} sort - Sort asc/desc
* @param {string} contractaddress - Address of ERC20 token contract (if not specified lists transfers for all tokens)
* @example
* var txlist = api.account.tokentx('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', '0x5F988D968cb76c34C87e6924Cc1Ef1dCd4dE75da', 1, 'latest', 'asc');
* @returns {Promise.<object>}
*/
tokentx(address, contractaddress, startblock, endblock, sort) {
const module = 'account';
const action = 'tokentx';

if (!startblock) {
startblock = 0;
}

if (!endblock) {
endblock = 'latest';
}

if (!sort) {
sort = 'asc';
}

var queryObject = {
module, action, startblock, endblock, sort, address, apiKey
};

if (contractaddress) {
queryObject.contractaddress = contractaddress;
}

return getRequest(querystring.stringify(queryObject));
}
};
};
12 changes: 12 additions & 0 deletions test/methods-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ describe('api', function() {
done();
});
});
it('tokentx', function(done){
var api = init();
var txlist = api.account.tokentx(
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
'0x6beb418fc6e1958204ac8baddcf109b8e9694966',
1, 'latest', 'asc'
);
txlist.then(function(res){
assert.ok(res);
done();
});
});
});
describe('stats', function(){
it('ethsupply', function(done){
Expand Down
16 changes: 16 additions & 0 deletions test/testnet-methods-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ describe('testnet methods', function () {
}).catch(done);
});

it('tokentx', function (done) {
/**
* No transaction found in testnet
* var txlist = api.account.txlist('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
*/
var txlist = api.account.tokentx(
'0x293bae8584ed8df4a0319d95ffef5fb3645a22b6',
'0x4fa5333ecfe1afca2624e14b039268c4591ef8b9'
);

txlist.then(function (res) {
assert.ok(res);
done();
}).catch(done);
});

xit('txlist', function (done) {
/**
* No transaction found in testnet
Expand Down

0 comments on commit ec0c448

Please sign in to comment.