Skip to content

Commit ec0c448

Browse files
author
mazikwyry
committed
Add tokentx action support to account module which allows getting a list of ERC20 tokes transfer events
1 parent d250805 commit ec0c448

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

lib/account.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,43 @@ module.exports = function(getRequest, apiKey) {
149149
module, action, address, apiKey
150150
});
151151
return getRequest(query);
152+
},
153+
/**
154+
* [BETA] Get a list of "ERC20 - Token Transfer Events" by Address
155+
* @param {string} address - Account address
156+
* @param {string} startblock - start looking here
157+
* @param {string} endblock - end looking there
158+
* @param {string} sort - Sort asc/desc
159+
* @param {string} contractaddress - Address of ERC20 token contract (if not specified lists transfers for all tokens)
160+
* @example
161+
* var txlist = api.account.tokentx('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', '0x5F988D968cb76c34C87e6924Cc1Ef1dCd4dE75da', 1, 'latest', 'asc');
162+
* @returns {Promise.<object>}
163+
*/
164+
tokentx(address, contractaddress, startblock, endblock, sort) {
165+
const module = 'account';
166+
const action = 'tokentx';
167+
168+
if (!startblock) {
169+
startblock = 0;
170+
}
171+
172+
if (!endblock) {
173+
endblock = 'latest';
174+
}
175+
176+
if (!sort) {
177+
sort = 'asc';
178+
}
179+
180+
var queryObject = {
181+
module, action, startblock, endblock, sort, address, apiKey
182+
};
183+
184+
if (contractaddress) {
185+
queryObject.contractaddress = contractaddress;
186+
}
187+
188+
return getRequest(querystring.stringify(queryObject));
152189
}
153190
};
154191
};

test/methods-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ describe('api', function() {
7676
done();
7777
});
7878
});
79+
it('tokentx', function(done){
80+
var api = init();
81+
var txlist = api.account.tokentx(
82+
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
83+
'0x6beb418fc6e1958204ac8baddcf109b8e9694966',
84+
1, 'latest', 'asc'
85+
);
86+
txlist.then(function(res){
87+
assert.ok(res);
88+
done();
89+
});
90+
});
7991
});
8092
describe('stats', function(){
8193
it('ethsupply', function(done){

test/testnet-methods-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ describe('testnet methods', function () {
4747
}).catch(done);
4848
});
4949

50+
it('tokentx', function (done) {
51+
/**
52+
* No transaction found in testnet
53+
* var txlist = api.account.txlist('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
54+
*/
55+
var txlist = api.account.tokentx(
56+
'0x293bae8584ed8df4a0319d95ffef5fb3645a22b6',
57+
'0x4fa5333ecfe1afca2624e14b039268c4591ef8b9'
58+
);
59+
60+
txlist.then(function (res) {
61+
assert.ok(res);
62+
done();
63+
}).catch(done);
64+
});
65+
5066
xit('txlist', function (done) {
5167
/**
5268
* No transaction found in testnet

0 commit comments

Comments
 (0)