在这个笔记中,我将使用Python命令行测试以太坊的RPC客户端,准备好狂敲键盘吧。过程中有关JSON RPC的更多信息,可以参阅JSON RPC。
输入:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
import sys
sys.version
输出:
'3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 12:22:00) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]'
准备环境
为以太坊安装Python RPC客户端,输入:
jitsejan@jjvps:~$ pip install ethereum-rpc-client
启动区块链以确保启用RPC。
输入:
jitsejan@jjvps:~$ geth --networkid 23 --nodiscover --maxpeers 0 --port 30333 --rpc
验证geth是否正在运行并且列出了该帐户。
输入:
!geth account list
输出:
Account #0: {8cf9deda0712f2291fb16739f8759e4a0a575854} keystore:///home/jitsejan/.ethereum/keystore/UTC--2017-05-01T14-58-43.532247863Z--8cf9deda0712f2291fb16739f8759e4a0a575854
链接到RPC客户端
输入:
from eth_rpc_client import Client
client = Client(host="127.0.0.1", port="8545")
检查客户端
输入:
import pdir
pdir(client)
输出:
abstract class:
__subclasshook__
attribute access:
__delattr__, __dir__, __getattribute__, __setattr__
class customization:
__init_subclass__
object customization:
__format__, __hash__, __init__, __new__, __repr__, __sizeof__, __str__
other:
_coinbase_cache, _coinbase_cache_til, _nonce, async_timeout, host, is_async, port, request_queue, request_thread, results, session
pickle:
__reduce__, __reduce_ex__
rich comparison:
__eq__, __ge__, __gt__, __le__, __lt__, __ne__
special attribute:
__class__, __dict__, __doc__, __module__, __weakref__
descriptor:
default_from_address: @