Skip to content

Commit 424fd3a

Browse files
committed
(docs): examples for api docs
1 parent ab00c1b commit 424fd3a

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

lib/init.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ module.exports = function (apiKey) {
3939
* @namespace
4040
*/
4141
log: {
42-
4342
/**
4443
* The Event Log API was designed to provide an alternative to the native eth_getLogs.
4544
*/
@@ -110,6 +109,8 @@ module.exports = function (apiKey) {
110109
proxy: {
111110
/**
112111
* Returns the number of most recent block
112+
* @example
113+
* var block = api.proxy.eth_blockNumber();
113114
* @returns {Promise.<integer>}
114115
*/
115116
eth_blockNumber() {
@@ -123,6 +124,8 @@ module.exports = function (apiKey) {
123124
/**
124125
* Returns information about a block by block number.
125126
* @param {string} tag - Tag to look up
127+
* @example
128+
* var blockNumber = api.proxy.eth_getBlockByNumber('0x10d4f');
126129
* @returns {Promise.<integer>}
127130
*/
128131
eth_getBlockByNumber(tag) {
@@ -138,6 +141,8 @@ module.exports = function (apiKey) {
138141
* Returns information about a uncle by block number.
139142
* @param {string} tag - Tag to look up
140143
* @param {string} index - Index
144+
* @example
145+
* var res = api.proxy.eth_getUncleByBlockNumberAndIndex('0x210A9B', '0x0');
141146
* @returns {Promise.<object>}
142147
*/
143148
eth_getUncleByBlockNumberAndIndex(tag, index) {
@@ -151,6 +156,8 @@ module.exports = function (apiKey) {
151156
/**
152157
* Returns the number of transactions in a block from a block matching the given block number
153158
* @param {string} tag - Tag to look up
159+
* @example
160+
* var res = api.proxy.eth_getBlockTransactionCountByNumber('0x10FB78');
154161
* @returns {Promise.<object>}
155162
*/
156163
eth_getBlockTransactionCountByNumber(tag) {
@@ -164,6 +171,8 @@ module.exports = function (apiKey) {
164171
/**
165172
* Returns the information about a transaction requested by transaction hash
166173
* @param {string} hash - Transaction hash
174+
* @example
175+
* var res = api.proxy.eth_getTransactionByHash('0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1');
167176
* @returns {Promise.<object>}
168177
*/
169178
eth_getTransactionByHash(hash) {
@@ -178,6 +187,8 @@ module.exports = function (apiKey) {
178187
* Returns information about a transaction by block number and transaction index position
179188
* @param {string} tag - Tag to look up
180189
* @param {string} index - Index
190+
* @example
191+
* var res = api.proxy.eth_getTransactionByBlockNumberAndIndex('0x10d4f', '0x0');
181192
* @returns {Promise.<object>}
182193
*/
183194
eth_getTransactionByBlockNumberAndIndex(tag, index) {
@@ -191,6 +202,8 @@ module.exports = function (apiKey) {
191202
/**
192203
* Returns the number of transactions sent from an address
193204
* @param {string} address - Address of the transaction
205+
* @example
206+
* var res = api.proxy.eth_getTransactionCount('0x2910543af39aba0cd09dbb2d50200b3e800a63d2', 'latest');
194207
* @returns {Promise.<object>}
195208
*/
196209
eth_getTransactionCount(address) {
@@ -204,6 +217,8 @@ module.exports = function (apiKey) {
204217
/**
205218
* Creates new message call transaction or a contract creation for signed transactions
206219
* @param {string} hex - Serialized Message
220+
* @example
221+
* var res = api.proxy.eth_sendRawTransaction('0xf904808000831cfde080');
207222
* @returns {Promise.<object>}
208223
*/
209224
eth_sendRawTransaction(hex) {
@@ -217,6 +232,8 @@ module.exports = function (apiKey) {
217232
/**
218233
* Returns the receipt of a transaction by transaction hash
219234
* @param {string} txhash - Transaction hash
235+
* @example
236+
* var ret = api.proxy.eth_getTransactionReceipt('0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1');
220237
* @returns {Promise.<object>}
221238
*/
222239
eth_getTransactionReceipt(txhash) {
@@ -231,6 +248,8 @@ module.exports = function (apiKey) {
231248
* Executes a new message call immediately without creating a transaction on the block chain
232249
* @param {string} to - Address to execute from
233250
* @param {string} tag - Content
251+
* @example
252+
* var res = api.proxy.eth_call('0xAEEF46DB4855E25702F8237E8f403FddcaF931C0', '0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724', 'latest');
234253
* @returns {Promise.<object>}
235254
*/
236255
eth_call(to, tag) {
@@ -245,6 +264,8 @@ module.exports = function (apiKey) {
245264
* Returns code at a given address
246265
* @param {string} address - Address to get code from
247266
* @param {string} tag - ??
267+
* @example
268+
* var res = api.proxy.eth_getCode('0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c', 'latest');
248269
* @returns {Promise.<object>}
249270
*/
250271
eth_getCode(address, tag) {
@@ -260,6 +281,8 @@ module.exports = function (apiKey) {
260281
* @param {string} address - Address to get code from
261282
* @param {string} position - Storage position
262283
* @param {string} tag - ??
284+
* @example
285+
* var res = api.proxy.eth_getStorageAt('0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd', '0x0', 'latest');
263286
* @returns {Promise.<object>}
264287
*/
265288
eth_getStorageAt(address, position, tag) {
@@ -272,6 +295,7 @@ module.exports = function (apiKey) {
272295
},
273296
/**
274297
* Returns the current price per gas in wei.
298+
* var gasprice = api.proxy.eth_gasPrice();
275299
* @returns {Promise.<object>}
276300
*/
277301
eth_gasPrice() {
@@ -288,6 +312,13 @@ module.exports = function (apiKey) {
288312
* @param {string} value - Storage position
289313
* @param {string} gasPrice - ??
290314
* @param {string} gas - ??
315+
* @xample
316+
* var res = api.proxy.eth_estimateGas(
317+
* '0xf0160428a8552ac9bb7e050d90eeade4ddd52843',
318+
* '0xff22',
319+
* '0x051da038cc',
320+
* '0xffffff'
321+
*);
291322
* @returns {Promise.<object>}
292323
*/
293324
eth_estimateGas(to, value, gasPrice, gas) {
@@ -307,6 +338,8 @@ module.exports = function (apiKey) {
307338
* Returns the supply of Tokens
308339
* @param {string} tokenname - Name of the Token
309340
* @param {string} contractaddress - Address from token contract
341+
* @example
342+
* var supply = api.stats.tokensupply(null, '0x57d90b64a1a57749b0f932f1a3395792e12e7055');
310343
* @returns {Promise.<object>}
311344
*/
312345
tokensupply(tokenname, contractaddress) {
@@ -331,6 +364,7 @@ module.exports = function (apiKey) {
331364

332365
/**
333366
* Returns total supply of ether
367+
* var supply = api.stats.ethsupply();
334368
* @returns {Promise.<integer>}
335369
*/
336370
ethsupply() {
@@ -344,6 +378,8 @@ module.exports = function (apiKey) {
344378

345379
/**
346380
* Returns the price of ether now
381+
* @example
382+
* var price = api.stats.ethprice();
347383
* @returns {Promise.<integer>}
348384
*/
349385
ethprice() {
@@ -402,6 +438,12 @@ module.exports = function (apiKey) {
402438
/**
403439
* Returns the ABI/Interface of a given contract
404440
* @param {string} address - Contract address
441+
* @example
442+
* api.contract
443+
* .getabi('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
444+
* .at('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
445+
* .memberId('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
446+
* .then(console.log)
405447
* @returns {Promise.<object>}
406448
*/
407449
getabi(address) {
@@ -424,6 +466,10 @@ module.exports = function (apiKey) {
424466
* @param {string} address - Contract address
425467
* @param {string} tokenname - Name of the token
426468
* @param {string} contractaddress - Contract address
469+
* @example
470+
* var supply = api.account.tokenbalance(
471+
* '0x0a869d79a7052c7f1b55a8ebabbea3420f0d1e13',
472+
* 'TheDAO');
427473
* @returns {Promise.<object>}
428474
*/
429475
tokenbalance(address, tokenname, contractaddress){
@@ -454,6 +500,8 @@ module.exports = function (apiKey) {
454500
/**
455501
* Returns the balance of a sepcific account
456502
* @param {string} address - Address
503+
* @example
504+
* var balance = api.account.balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae');
457505
* @returns {Promise.<object>}
458506
*/
459507
balance(address) {
@@ -474,6 +522,8 @@ module.exports = function (apiKey) {
474522
/**
475523
* Get a list of internal transactions
476524
* @param {string} txhash - Transaction hash
525+
* @example
526+
* var txlist = api.account.txlistinternal('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170');
477527
* @returns {Promise.<object>}
478528
*/
479529
txlistinternal(txhash) {
@@ -492,6 +542,8 @@ module.exports = function (apiKey) {
492542
* @param {string} startblock - start looking here
493543
* @param {string} endblock - end looking there
494544
* @param {string} sort - Sort asc/desc
545+
* @example
546+
* var txlist = api.account.txlist('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', 1, 'latest', 'asc');
495547
* @returns {Promise.<object>}
496548
*/
497549
txlist(address, startblock, endblock, sort) {
@@ -518,6 +570,8 @@ module.exports = function (apiKey) {
518570
},
519571
/**
520572
* Get a list of blocks that a specific account has mineds
573+
* @example
574+
* var txlist = api.account.getminedblocks('0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b');
521575
* @param {string} address - Transaction hash
522576
*/
523577
getminedblocks(address) {

test/methods-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe('api', function() {
146146

147147
it('proxy.eth_getBlockByNumber', function(done){
148148
var api = init();
149-
var res = api.proxy.eth_getBlockByNumber('0x10d4f', true);
149+
var res = api.proxy.eth_getBlockByNumber('0x10d4f');
150150
res.then(function(res){
151151
assert.ok(res);
152152
done();

0 commit comments

Comments
 (0)