Skip to content

Commit cc1af67

Browse files
authored
Merge pull request sebs#95 from mochimisu/master
support for etherscan's tokennfttx api for ERC721 tokens
2 parents c79752b + 80f85f0 commit cc1af67

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

lib/account.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,54 @@ module.exports = function(getRequest, apiKey) {
209209
}
210210

211211
return getRequest(querystring.stringify(queryObject));
212-
}
212+
},
213+
214+
/**
215+
* [BETA] Get a list of "ERC721 - Token Transfer Events" by Address
216+
* @param {string} address - Account address
217+
* @param {string} startblock - start looking here
218+
* @param {string} endblock - end looking there
219+
* @param {number} page - Page number
220+
* @param {number} offset - Max records to return
221+
* @param {string} sort - Sort asc/desc
222+
* @param {string} contractaddress - Address of ERC721 token contract (if not specified lists transfers for all tokens)
223+
* @example
224+
* var txlist = api.account.tokenftntx('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', '0x5F988D968cb76c34C87e6924Cc1Ef1dCd4dE75da', 1, 'latest', 'asc');
225+
* @returns {Promise.<object>}
226+
*/
227+
tokennfttx(address, contractaddress, startblock, endblock, page, offset, sort) {
228+
const module = 'account';
229+
const action = 'tokennfttx';
230+
231+
if (!startblock) {
232+
startblock = 0;
233+
}
234+
235+
if (!endblock) {
236+
endblock = 'latest';
237+
}
238+
239+
if (!page) {
240+
page = 1;
241+
}
242+
243+
if (!offset) {
244+
offset = 100;
245+
}
246+
247+
if (!sort) {
248+
sort = 'asc';
249+
}
250+
251+
var queryObject = {
252+
module, action, startblock, endblock, page, offset, sort, address, apiKey
253+
};
254+
255+
if (contractaddress) {
256+
queryObject.contractaddress = contractaddress;
257+
}
258+
259+
return getRequest(querystring.stringify(queryObject));
260+
}
213261
};
214262
};

test/methods-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ describe('api', function() {
8888
done();
8989
});
9090
});
91+
it('tokennfttx', function(done){
92+
var api = init();
93+
var txlist = api.account.tokentx(
94+
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
95+
'0x6beb418fc6e1958204ac8baddcf109b8e9694966',
96+
1, 'latest', 'asc'
97+
);
98+
txlist.then(function(res){
99+
assert.ok(res);
100+
done();
101+
});
102+
});
91103
});
92104
describe('stats', function(){
93105
it('ethsupply', function(done){

0 commit comments

Comments
 (0)