forked from sebs/etherscan-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.js
More file actions
214 lines (184 loc) · 5.92 KB
/
account.js
File metadata and controls
214 lines (184 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
const querystring = require('querystring');
module.exports = function(getRequest, apiKey) {
return {
/**
* Returns the amount of Tokens a specific account owns.
* @param {string} address - Contract address
* @param {string} tokenname - Name of the token
* @param {string} contractaddress - Contract address
* @example
* var supply = api.account.tokenbalance(
* '0x4366ddc115d8cf213c564da36e64c8ebaa30cdbd',
* '',
* '0xe0b7927c4af23765cb51314a0e0521a9645f0e2a' // DGD contract address
* );
* @returns {Promise.<object>}
*/
tokenbalance(address, tokenname, contractaddress) {
const module = 'account';
const action = 'tokenbalance';
const tag = 'latest';
var queryObject = {
module, action, apiKey, tag
};
if (contractaddress) {
queryObject.contractaddress = contractaddress;
}
if (tokenname) {
queryObject.tokenname = tokenname;
}
if (address) {
queryObject.address = address;
}
var query = querystring.stringify(queryObject);
return getRequest(query);
},
/**
* Returns the balance of a sepcific account
* @param {string} address - Address
* @example
* var balance = api.account.balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
* @returns {Promise.<object>}
*/
balance(address) {
const module = 'account';
let action = 'balance';
const tag = 'latest';
if (typeof address !== 'string' && address && address.length) {
address = address.join(',');
action = 'balancemulti';
}
var query = querystring.stringify({
module, action, tag, address, apiKey
});
return getRequest(query);
},
/**
* Get a list of internal transactions
* @param {string} txhash - Transaction hash. If specified then address will be ignored
* @param {string} address - Transaction address
* @param {string} startblock - start looking here
* @param {string} endblock - end looking there
* @param {string} sort - Sort asc/desc
* @example
* var txlist = api.account.txlistinternal('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170');
* @returns {Promise.<object>}
*/
txlistinternal(txhash, address, startblock, endblock, sort) {
const module = 'account';
const action = 'txlistinternal';
var queryObject = {
module,
action,
apiKey
};
if (!startblock) {
startblock = 0;
}
queryObject.startblock = startblock;
if (!endblock) {
endblock = 'latest';
}
queryObject.endblock = endblock;
if (!sort) {
sort = 'asc';
}
queryObject.sort = sort;
if (txhash) {
queryObject.txhash = txhash;
} else {
queryObject.address = address;
}
queryObject.txhash = txhash;
return getRequest(querystring.stringify(queryObject));
},
/**
* Get a list of transactions for a specfic address
* @param {string} address - Transaction address
* @param {string} startblock - start looking here
* @param {string} endblock - end looking there
* @param {number} page - Page number
* @param {number} offset - Max records to return
* @param {string} sort - Sort asc/desc
* @example
* var txlist = api.account.txlist('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', 1, 'latest', 1, 100, 'asc');
* @returns {Promise.<object>}
*/
txlist(address, startblock, endblock, page, offset, sort) {
const module = 'account';
const action = 'txlist';
if (!startblock) {
startblock = 0;
}
if (!endblock) {
endblock = 'latest';
}
if (!page) {
page = 1;
}
if (!offset) {
offset = 100;
}
if (!sort) {
sort = 'asc';
}
var query = querystring.stringify({
module, action, startblock, endblock, page, offset, sort, address, apiKey
});
return getRequest(query);
},
/**
* Get a list of blocks that a specific account has mineds
* @example
* var txlist = api.account.getminedblocks('0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b');
* @param {string} address - Transaction hash
*/
getminedblocks(address) {
const module = 'account';
const action = 'getminedblocks';
var query = querystring.stringify({
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 {number} page - Page number
* @param {number} offset - Max records to return
* @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, page, offset, sort) {
const module = 'account';
const action = 'tokentx';
if (!startblock) {
startblock = 0;
}
if (!endblock) {
endblock = 'latest';
}
if (!page) {
page = 1;
}
if (!offset) {
offset = 100;
}
if (!sort) {
sort = 'asc';
}
var queryObject = {
module, action, startblock, endblock, page, offset, sort, address, apiKey
};
if (contractaddress) {
queryObject.contractaddress = contractaddress;
}
return getRequest(querystring.stringify(queryObject));
}
};
};