-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweb3-eth.rst
1981 lines (1264 loc) · 60 KB
/
web3-eth.rst
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.. _eth:
========
web3.eth
========
``web3-eth`` 包用来与以太坊区块链和以太坊智能合约进行交互。
.. code-block:: javascript
var Eth = require('web3-eth');
// "Eth.providers.givenProvider" 在支持以太坊的浏览器上会被设置
var eth = new Eth(Eth.givenProvider || 'ws://some.local-or-remote.node:8546');
// 或者使用 web3 旗下的包
var Web3 = require('web3');
var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546');
// -> web3.eth
Note on checksum addresses
============================
本包中函数所返回的以太坊地址均为校验和地址。
这意味着地址中有些字母是大写的而有些是小些的。
基于此可以计算地址的校验和并以此证明它的正确性。
校验和不正确的地址在传入函数时会抛错。
你可以使用全大写或全小写的地址来绕过校验和检查。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getAccounts(console.log);
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe" ,"0x85F43D8a49eeB85d32Cf465507DD71d507100C1d"]
------------------------------------------------------------------------------
subscribe
=====================
关于 ``web3.eth.subscribe``,可以参考 :ref:`Subscribe reference documentation <eth-subscribe>`
------------------------------------------------------------------------------
Contract
=====================
关于 ``web3.eth.Contract``,可以参考 :ref:`Contract reference documentation <eth-contract>`
------------------------------------------------------------------------------
Iban
=====================
关于 ``web3.eth.Iban``,可以参考 :ref:`Iban reference documentation <eth-iban>`
------------------------------------------------------------------------------
personal
=====================
关于 ``web3.eth.personal``, 可以参考 :ref:`personal reference documentation <eth-personal>`
------------------------------------------------------------------------------
accounts
=====================
关于 ``web3.eth.accounts``, 可以参考 :ref:`accounts reference documentation <eth-accounts>`
------------------------------------------------------------------------------
ens
=====================
关于 ``web3.eth.ens``, 可以参考 :ref:`ENS reference documentation <eth-ens>`
------------------------------------------------------------------------------
abi
=====================
关于 ``web3.eth.abi``, 可以参考 :ref:`ABI reference documentation <eth-abi>`
------------------------------------------------------------------------------
net
=====================
关于 ``web3.eth.net``, 可以参考 :ref:`net reference documentation <eth-net>`
------------------------------------------------------------------------------
.. include:: include_package-core.rst
------------------------------------------------------------------------------
.. _eth-defaultaccount
defaultAccount
=====================
.. code-block:: javascript
web3.eth.defaultAccount
如果下面这些方法没有指定 ``"from"`` 属性,则使用该地址作为默认的 ``"from"`` 属性值。
- :ref:`web3.eth.sendTransaction() <eth-sendtransaction>`
- :ref:`web3.eth.call() <eth-call>`
- :ref:`new web3.eth.Contract() -> myContract.methods.myMethod().call() <eth-contract-call>`
- :ref:`new web3.eth.Contract() -> myContract.methods.myMethod().send() <eth-contract-send>`
--------
属性
--------
``String`` - 20 字节: 任意以太坊地址。 该地址对应的私钥应该保存在你的以太坊节点或 keystore 文件中。 (默认值为 ``undefined``)
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.defaultAccount;
> undefined
// 设置默认账号
web3.eth.defaultAccount = '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe';
------------------------------------------------------------------------------
.. _eth-defaultblock:
defaultBlock
=====================
.. code-block:: javascript
web3.eth.defaultBlock
一些特定方法所使用的默认区块号。 你可以通过这些方法的最后一个参数传递一个值来覆盖这个默认设置。
默认值为 "latest"。
- :ref:`web3.eth.getBalance() <eth-getbalance>`
- :ref:`web3.eth.getCode() <eth-getcode>`
- :ref:`web3.eth.getTransactionCount() <eth-gettransactioncount>`
- :ref:`web3.eth.getStorageAt() <eth-getstorageat>`
- :ref:`web3.eth.call() <eth-call>`
- :ref:`new web3.eth.Contract() -> myContract.methods.myMethod().call() <eth-contract-call>`
----------
属性
----------
默认区块参数值可以下面中的一个:
- ``Number|BN|BigNumber``: 指定区块号
- ``"genesis"`` - ``String``: 创世区块
- ``"latest"`` - ``String``: 最新区块 (区块链的头号区块)
- ``"pending"`` - ``String``: 正要挖到的区块 (包括待处理交易)
- ``"earliest"`` - ``String``: 创世区块
默认值为 ``"latest"``
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.defaultBlock;
> "latest"
// 设置默认区块
web3.eth.defaultBlock = 231;
------------------------------------------------------------------------------
.. _eth-defaulthardfork:
defaultHardfork
=====================
.. code-block:: javascript
web3.eth.defaultHardfork
签名交易时所使用的硬分叉属性。
----------
属性
----------
默认硬分叉属性可以是下面中的一个:
- ``"chainstart"`` - ``String``
- ``"homestead"`` - ``String``
- ``"dao"`` - ``String``
- ``"tangerineWhistle"`` - ``String``
- ``"spuriousDragon"`` - ``String``
- ``"byzantium"`` - ``String``
- ``"constantinople"`` - ``String``
- ``"petersburg"`` - ``String``
- ``"istanbul"`` - ``String``
默认值为 ``"petersburg"``
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.defaultHardfork;
> "petersburg"
// 设置默认硬分叉
web3.eth.defaultHardfork = 'istanbul';
------------------------------------------------------------------------------
.. _eth-defaultchain:
defaultChain
=====================
.. code-block:: javascript
web3.eth.defaultChain
签名交易时所用的默认链属性
----------
属性
----------
默认链属性可以是下面中的一个:
- ``"mainnet"`` - ``String``
- ``"goerli"`` - ``String``
- ``"kovan"`` - ``String``
- ``"rinkeby"`` - ``String``
- ``"ropsten"`` - ``String``
默认值为 ``"mainnet"``
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.defaultChain;
> "mainnet"
// 设置默认链
web3.eth.defaultChain = 'goerli';
------------------------------------------------------------------------------
.. _eth-defaultcommon:
defaultCommon
=====================
.. code-block:: javascript
web3.eth.defaultCommon
签名交易时所使用的默认通用属性。
----------
属性
----------
默认通用属性包含下面这样的 ``Common`` 对象:
- ``customChain`` - ``Object``: 自定义链属性
- ``name`` - ``string``: (可选) 链名称
- ``networkId`` - ``number``: 自定义链的网络 ID
- ``chainId`` - ``number``: 自定义链的链 ID
- ``baseChain`` - ``string``: (可选) ``mainnet``, ``goerli``, ``kovan``, ``rinkeby``, or ``ropsten``
- ``hardfork`` - ``string``: (可选) ``chainstart``, ``homestead``, ``dao``, ``tangerineWhistle``, ``spuriousDragon``, ``byzantium``, ``constantinople``, ``petersburg``, or ``istanbul``
默认值为 ``undefined``。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.defaultCommon;
> {customChain: {name: 'custom-network', chainId: 1, networkId: 1}, baseChain: 'mainnet', hardfork: 'petersburg'}
// 设置默认通用属性
web3.eth.defaultCommon = {customChain: {name: 'custom-network', chainId: 1, networkId: 1}, baseChain: 'mainnet', hardfork: 'petersburg'};
------------------------------------------------------------------------------
.. _web3-module-transactionblocktimeout:
transactionBlockTimeout
=========================
.. code-block:: javascript
web3.eth.transactionBlockTimeout
``transactionBlockTimeout`` 会被用在基于套接字的连接上。该属性定义了直到第一次确认发生交易应该等待的区块数。
这意味着当超时发生时,PromiEvent 会拒绝并显示超时错误。
-------
返回值
-------
``number``: transactionBlockTimeout 当前值 (默认值: 50)
------------------------------------------------------------------------------
.. _web3-module-transactionconfirmationblocks:
transactionConfirmationBlocks
===================================
.. code-block:: javascript
web3.eth.transactionConfirmationBlocks
一笔交易被认为已确认所需要的区块数
-------
返回值
-------
``number``: transactionConfirmationBlocks 当前值 (默认值: 24)
------------------------------------------------------------------------------
.. _web3-module-transactionpollingtimeout:
transactionPollingTimeout
============================
.. code-block:: javascript
web3.eth.transactionPollingTimeout
``transactionPollingTimeout`` 在基于 HTTP 的连接上使用。
这个选项定义了 Web3 等待网络挖出交易的确认收据的秒数。注意:当此种超时发生时,交易可能仍未完成。
-------
返回值
-------
``number``: transactionPollingTimeout 当前值 (默认值: 750)
------------------------------------------------------------------------------
.. _web3-module-handlerevert:
handleRevert
============
.. code-block:: javascript
web3.eth.handleRevert
``handleRevert`` 默认值为 ``false``,如果在调用下面这些方法时启用,将返回回退原因字符串:
- :ref:`web3.eth.call() <eth-call>`
- :ref:`web3.eth.sendTransaction() <eth-sendtransaction>`
- :ref:`contract.methods.myMethod(...).send(...) <contract-send>`
- :ref:`contract.methods.myMethod(...).call(...) <contract-call>`
.. note:: 回退原因字符串和签名会作为返回错误的属性存在。
-------
返回值
-------
``boolean``: ``handleRevert`` 当前值 (默认值: false)
------------------------------------------------------------------------------
getProtocolVersion
=====================
.. code-block:: javascript
web3.eth.getProtocolVersion([callback])
返回节点的以太坊协议版本。
-------
返回值
-------
``Promise`` 返回 ``String``: 协议版本。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getProtocolVersion()
.then(console.log);
> "63"
------------------------------------------------------------------------------
isSyncing
=====================
.. code-block:: javascript
web3.eth.isSyncing([callback])
检测当前节点是否正在进行数据同步,返回一个同步对象或``false``。
.. _eth-issyncing-return:
-------
返回值
-------
``Promise`` 返回 ``Object|Boolean`` - 当节点正在进行数据同步时返回同步对象,否则返回 ``false``:
- ``startingBlock`` - ``Number``: 同步开启时的区块号。
- ``currentBlock`` - ``Number``: 节点已经同步到的区块号。
- ``highestBlock`` - ``Number``: 预计会同步到的区块号。
- ``knownStates`` - ``Number``: 预计要下载的状态数据。
- ``pulledStates`` - ``Number``: 已经下载的状态数据。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.isSyncing()
.then(console.log);
> {
startingBlock: 100,
currentBlock: 312,
highestBlock: 512,
knownStates: 234566,
pulledStates: 123455
}
------------------------------------------------------------------------------
getCoinbase
=====================
.. code-block:: javascript
getCoinbase([callback])
返回用来收取挖矿奖励的 coinbase 地址。
-------
返回值
-------
``Promise`` 返回 ``String`` - 20 个字节: 在节点中设置的用来挖矿的 coinbase 地址。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getCoinbase()
.then(console.log);
> "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe"
------------------------------------------------------------------------------
isMining
=====================
.. code-block:: javascript
web3.eth.isMining([callback])
检测节点是否正在挖矿。
-------
返回值
-------
``Promise`` 返回 ``Boolean``: 如果节点正在挖矿返回 ``true`` ,否则返回 ``false``。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.isMining()
.then(console.log);
> true
------------------------------------------------------------------------------
getHashrate
=====================
.. code-block:: javascript
web3.eth.getHashrate([callback])
返回节点每秒所挖的哈希数。
-------
返回值
-------
``Promise`` 返回 ``Number``: 每秒哈希数。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getHashrate()
.then(console.log);
> 493736
------------------------------------------------------------------------------
.. _eth-gasprice:
getGasPrice
=====================
.. code-block:: javascript
web3.eth.getGasPrice([callback])
返回当前 gas 价格预言机。
gas 价格由最后几个区块 gas 价格的中位数确定。
-------
返回值
-------
``Promise`` 返回 ``String`` - 当前以 :ref:`wei <what-is-wei>` 为单位的 gas 价格。
可以参考 :ref:`关于使用 JavaScript 大数处理的注解 <utils-bn>`.
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getGasPrice()
.then(console.log);
> "20000000000"
------------------------------------------------------------------------------
getAccounts
=====================
.. code-block:: javascript
web3.eth.getAccounts([callback])
返回节点所控制的账户列表。
-------
返回值
-------
``Promise`` 返回 ``Array`` - 节点所控制的节点数组。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getAccounts()
.then(console.log);
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]
------------------------------------------------------------------------------
getBlockNumber
=====================
.. code-block:: javascript
web3.eth.getBlockNumber([callback])
返回当前区块号。
-------
返回值
-------
``Promise`` 返回 ``Number`` - 最近区块号。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getBlockNumber()
.then(console.log);
> 2744
------------------------------------------------------------------------------
getBalance
=====================
.. code-block:: javascript
web3.eth.getBalance(address [, defaultBlock] [, callback])
返回地址在指定区块的余额。
----------
参数
----------
1. ``String`` - 要获取余额的地址。
2. ``Number|String|BN|BigNumber`` - (可选) 如果传入该参数,则会覆盖通过 :ref:`web3.eth.defaultBlock <eth-defaultblock>` 设置的默认区块。 也可以使用像 ``"latest"``, ``"earliest"``, ``"pending"``, and ``"genesis"`` 这种预先设置的区块号。
3. ``Function`` - (可选) 可选的回调函数,其第一个参数为错误对象,第二个参数为函数运行结果。
-------
返回值
-------
``Promise`` 返回 ``String`` - 给定地址的当前账户余额,以 :ref:`wei <what-is-wei>` 为单位。
可以参考 :ref:`使用 Javascript 进行大数运算 <big-numbers-in-javascript>`.
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
.then(console.log);
> "1000000000000"
------------------------------------------------------------------------------
getStorageAt
=====================
.. code-block:: javascript
web3.eth.getStorageAt(address, position [, defaultBlock] [, callback])
获取地址在某个特定位置的存储值。
----------
参数
----------
1. ``String`` - 用来获取存储值的地址。
2. ``Number|String|BN|BigNumber`` - 存储的索引位置。
3. ``Number|String|BN|BigNumber`` - (可选) 如果传入值则会覆盖通过 :ref:`web3.eth.defaultBlock <eth-defaultblock>` 设置的默认区块号。预定义的区块号可以使用 ``"latest"``, ``"earliest"`` ``"pending"``, 和 ``"genesis"`` 等值。
4. ``Function`` - (可选) 可选的回调函数,其第一个参数为错误对象,第二个参数为函数运行结果。
-------
返回值
-------
``Promise`` 返回 ``String`` - 给定位置的存储值。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getStorageAt("0x407d73d8a49eeb85d32cf465507dd71d507100c1", 0)
.then(console.log);
> "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"
------------------------------------------------------------------------------
getCode
=====================
.. code-block:: javascript
web3.eth.getCode(address [, defaultBlock] [, callback])
获取特定地址关联的代码。
----------
参数
----------
1. ``String`` - 获取代码所需要的地址。
2. ``Number|String|BN|BigNumber`` - (可选) 如果传入值则会覆盖通过 :ref:`web3.eth.defaultBlock <eth-defaultblock>` 设置的默认区块号。预定义的区块号 ``"latest"``, ``"earliest"`` ``"pending"``, 和 ``"genesis"`` 等也可以使用。
3. ``Function`` - (可选) 可选的回调函数,其第一个参数为错误对象,第二个参数为函数运行结果。
-------
返回值
-------
``Promise`` 返回 ``String`` - 给定地址的代码数据。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8")
.then(console.log);
> "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
------------------------------------------------------------------------------
.. _eth-getblock:
getBlock
=====================
.. code-block:: javascript
web3.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])
返回与区块号或区块哈希匹配的区块。
----------
参数
----------
1. ``String|Number|BN|BigNumber`` - 区块号或区块哈希。 或者是 ``"genesis"``、 ``"latest"``、 ``"earliest"`` 、 ``"pending"`` 等在 :ref:`默认区块参数 <eth-defaultblock>` 中定义的字符串。
2. ``Boolean`` - (可选, 默认值 ``false``) 如果设定为 ``true``,返回的区块会包含完整的交易对象。 默认值为 ``false`` ,没必要特别设置为 false 了。 如果设置为 false,则返回的区块中仅包含交易哈希值。
3. ``Function`` - (可选) 可选的回调函数,其第一个参数为错误对象,第二个参数为函数运行结果。
-------
返回值
-------
``Promise`` 返回 ``Object`` - 区块对象:
- ``number`` - ``Number``: 区块号。 打包中的区块其值为 ``null``。
- ``hash`` 32 字节 - ``String``: Hash of the block. 打包中的区块其值为 ``null``。
- ``parentHash`` 32 字节 - ``String``: 父区块哈希值。
- ``nonce`` 8 Bytes - ``String``: 所生成的工作量证明哈希值。打包中的区块其值为 ``null``。
- ``sha3Uncles`` 32 字节 - ``String``: 区块中叔块数据的 SHA3 哈希值。
- ``logsBloom`` 256 Bytes - ``String``: 区块日志的布隆过滤器。打包中的区块其值为 ``null``。
- ``transactionsRoot`` 32 字节 - ``String``: 区块中交易 trie 树的根哈希。
- ``stateRoot`` 32 字节 - ``String``: 区块中状态 trie 树的根哈希。
- ``miner`` - ``String``: 获得挖矿奖励的受益人地址。
- ``difficulty`` - ``String``: 该区块难度值。
- ``totalDifficulty`` - ``String``: 到此区块为止链的总难度值。
- ``extraData`` - ``String``: 区块补充数据字段。
- ``size`` - ``Number``: 该区块的字节数大小。
- ``gasLimit`` - ``Number``: 该区块允许的最大 gas 消耗量。
- ``gasUsed`` - ``Number``: 该区块所有交易所消耗的 gas 总量。
- ``timestamp`` - ``Number``: 区块生成时的时间戳。
- ``transactions`` - ``Array``: 交易对象数组, 或者基于 ``returnTransactionObjects`` 参数的 32 字节交易哈希。
- ``uncles`` - ``Array``: 叔块哈希数组。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getBlock(3150)
.then(console.log);
> {
"number": 3,
"hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
"parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88",
"nonce": "0xfb6e1a62d119228b",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"transactionsRoot": "0x3a1b03875115b79539e5bd33fb00d8f7b7cd61929d5a3c574f507b8acf415bee",
"stateRoot": "0xf1133199d44695dfa8fd1bcfe424d82854b5cebef75bddd7e40ea94cda515bcb",
"miner": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty": '21345678965432',
"totalDifficulty": '324567845321',
"size": 616,
"extraData": "0x",
"gasLimit": 3141592,
"gasUsed": 21662,
"timestamp": 1429287689,
"transactions": [
"0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b"
],
"uncles": []
}
------------------------------------------------------------------------------
getBlockTransactionCount
============================
.. code-block:: javascript
web3.eth.getBlockTransactionCount(blockHashOrBlockNumber [, callback])
返回区块中包含的交易数量。
----------
参数
----------
1. ``String|Number|BN|BigNumber`` - 区块号或区块哈希。 或者像 ``"genesis"``, ``"latest"``, ``"earliest"``, or ``"pending"`` 这些在 :ref:`默认区块参数 <eth-defaultblock>` 中指定的字符串。
2. ``Function`` - (可选) 可选的回调函数,其第一个参数为错误对象,第二个参数为函数运行结果。
-------
返回值
-------
``Promise`` 返回 ``Number`` - 区块中包含的交易数量。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getBlockTransactionCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
.then(console.log);
> 1
------------------------------------------------------------------------------
getBlockUncleCount
=====================
.. code-block:: javascript
web3.eth.getBlockUncleCount(blockHashOrBlockNumber [, callback])
返回区块中包含的叔块数量。
----------
参数
----------
1. ``String|Number|BN|BigNumber`` - 区块号或区块哈希。 或者像 ``"genesis"``, ``"latest"``, ``"earliest"``, or ``"pending"`` 这些在 :ref:`默认区块参数 <eth-defaultblock>` 中指定的字符串。
2. ``Function`` - (可选) 可选的回调函数,其第一个参数为错误对象,第二个参数为函数运行结果。
-------
返回值
-------
``Promise`` 返回 ``Number`` - 区块中包含的叔块数量。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getBlockUncleCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1")
.then(console.log);
> 1
------------------------------------------------------------------------------
getUncle
=====================
.. code-block:: javascript
web3.eth.getUncle(blockHashOrBlockNumber, uncleIndex [, returnTransactionObjects] [, callback])
根据给定叔块索引返回对应叔块。
----------
参数
----------
1. ``String|Number|BN|BigNumber`` - 区块号或区块哈希。 或者像 ``"genesis"``, ``"latest"``, ``"earliest"``, or ``"pending"`` 这些在 :ref:`默认区块参数 <eth-defaultblock>` 中指定的字符串。
2. ``Number`` - 叔块位置索引。
3. ``Boolean`` - (可选, 默认值 ``false``) 如果设定为 ``true``,返回的区块会包含完整的交易对象。 默认值为 ``false`` ,没必要特别设置为 false 了。 如果设置为 false,则返回的区块中仅包含交易哈希值。
4. ``Function`` - (可选) 可选的回调函数,其第一个参数为错误对象,第二个参数为函数运行结果。
-------
返回值
-------
``Promise`` 返回 ``Object`` - 返回的叔块对象。 具体返回值可查看 :ref:`web3.eth.getBlock() <eth-getblock>`。
.. note:: 叔块不包含任何交易。
-----------
代码示例
-----------
.. code-block:: javascript
web3.eth.getUncle(500, 0)
.then(console.log);
> // 查看 web3.eth.getBlock