Skip to content

Commit fa1102e

Browse files
authored
Merge pull request ethereum#930 from bartleyg/provider-docs-updates
Add documentation for gethdev and infura autoprovider shortcuts
2 parents 914bc79 + f17da2a commit fa1102e

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

Diff for: docs/middleware.rst

+15-3
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,27 @@ Geth-style Proof of Authority
322322

323323
This middleware is required to connect to ``geth --dev`` or the Rinkeby public network.
324324

325-
For example, to connect to a local ``geth --dev`` instance on Linux:
325+
The easiest way to connect to a default ``geth --dev`` instance which loads the middleware is:
326+
327+
328+
.. code-block:: python
329+
330+
>>> from web3.auto.gethdev import w3
331+
332+
# confirm that the connection succeeded
333+
>>> w3.version.node
334+
'Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9'
335+
336+
This example connects to a local ``geth --dev`` instance on Linux with a
337+
unique IPC location and loads the middleware:
326338

327339

328340
.. code-block:: python
329341
330342
>>> from web3 import Web3, IPCProvider
331343
332-
# connect to the default geth --dev IPC location
333-
>>> w3 = Web3(IPCProvider('/tmp/geth.ipc'))
344+
# connect to the IPC location started with 'geth --dev --datadir ~/mynode'
345+
>>> w3 = Web3(IPCProvider('~/mynode/geth.ipc'))
334346
335347
>>> from web3.middleware import geth_poa_middleware
336348

Diff for: docs/providers.rst

+39-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,45 @@ Valid formats for the this environment variable are:
145145
- ``file:///path/to/node/rpc-json/file.ipc``
146146
- ``http://192.168.1.2:8545``
147147
- ``https://node.ontheweb.com``
148+
- ``ws://127.0.0.1:8546``
148149

149150

151+
Auto-initialization Provider Shortcuts
152+
--------------------------------------
153+
154+
There are a couple auto-initialization shortcuts for common providers.
155+
156+
Infura Mainnet
157+
~~~~~~~~~~~~~~
158+
159+
To easily connect to the Infura Mainnet remote node, first register for a free
160+
API key if you don't have one at https://infura.io/signup .
161+
162+
Then set the environment variable ``INFURA_API_KEY`` with your API key::
163+
164+
$ export INFURA_API_KEY=YourApiKey
165+
166+
.. code-block:: python
167+
168+
>>> from web3.auto.infura import w3
169+
170+
# confirm that the connection succeeded
171+
>>> w3.isConnected()
172+
True
173+
174+
Geth dev Proof of Authority
175+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
176+
177+
To connect to a ``geth --dev`` Proof of Authority instance with defaults:
178+
179+
.. code-block:: python
180+
181+
>>> from web3.auto.gethdev import w3
182+
183+
# confirm that the connection succeeded
184+
>>> w3.isConnected()
185+
True
186+
150187
Built In Providers
151188
------------------
152189

@@ -171,7 +208,7 @@ HTTPProvider
171208
.. code-block:: python
172209
173210
>>> from web3 import Web3
174-
>>> web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545")
211+
>>> web3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))
175212
176213
Note that you should create only one HTTPProvider per python
177214
process, as the HTTPProvider recycles underlying TCP/IP network connections,
@@ -236,7 +273,7 @@ WebsocketProvider
236273
.. code-block:: python
237274
238275
>>> from web3 import Web3
239-
>>> web3 = Web3(Web3.WebsocketProvider("ws://127.0.0.1:8546")
276+
>>> web3 = Web3(Web3.WebsocketProvider("ws://127.0.0.1:8546"))
240277
241278
Under the hood, the ``WebsocketProvider`` uses the python websockets library for
242279
making requests. If you would like to modify how requests are made, you can

0 commit comments

Comments
 (0)