mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 10:56:47 +00:00
expand docs a little
This commit is contained in:
parent
ecd4cd3eb4
commit
e20995a96d
@ -46,6 +46,25 @@ Delegated Signing Manager
|
||||
that does not need to be connected or synced with the network.
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# setup RPC provider connected to infura.
|
||||
>>> web3 = Web3(Web3.RPCProvider(host='mainnet.infura.io', path='your-infura-access-key'))
|
||||
# create second manager connected to local node (which must be unlocked)
|
||||
>>> signature_manager = web3.RequestManager(IPCProvider())
|
||||
# Setup the signing manager.
|
||||
>>> delegated_manager = Web3.DelegatedSigningManager(web3._requestManager, signature_manager)
|
||||
>>> web3.setManager(delegated_manager)
|
||||
>>> web3.eth.sendTransaction({
|
||||
... 'from': '0x...'
|
||||
... ...
|
||||
... })
|
||||
|
||||
In this example the transaction will be signed using the locally unlocked IPC
|
||||
node and then the public Infura RPC node is used relay the pre-signed
|
||||
transaction to the network using the ``eth_sendRawTransaction`` method.
|
||||
|
||||
|
||||
Private Key Signing Manager
|
||||
---------------------------
|
||||
|
||||
@ -62,3 +81,19 @@ Private Key Signing Manager
|
||||
|
||||
This method registers a private key with the manager which will allow
|
||||
sending from the derived address.
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> web3 = Web3(Web3.RPCProvider(host='mainnet.infura.io', path='your-infura-access-key'))
|
||||
>>> pk_manager = Web3.PrivateKeySigningManager(web3._requestManager)
|
||||
>>> pk_manager.register_private_key(b'the-private-key-as-bytes')
|
||||
>>> web3.setManager(pk_manager)
|
||||
>>> web3.eth.sendTransaction({
|
||||
... 'from': '0x...' # the public address for the registered private key.
|
||||
... ...
|
||||
... })
|
||||
|
||||
In this example, the transaction will be signed using the private key it was
|
||||
given, after which it will be sent using the ``eth_sendRawTransaction`` through
|
||||
the connected Infura RPC node.
|
||||
|
||||
22
web3/main.py
22
web3/main.py
@ -17,7 +17,11 @@ from web3.providers.rpc import (
|
||||
TestRPCProvider,
|
||||
)
|
||||
from web3.providers.ipc import IPCProvider
|
||||
from web3.providers.manager import RequestManager
|
||||
from web3.providers.manager import (
|
||||
RequestManager,
|
||||
DelegatedSigningManager,
|
||||
PrivateKeySigningManager,
|
||||
)
|
||||
|
||||
from web3.utils.functional import (
|
||||
compose,
|
||||
@ -44,10 +48,16 @@ from web3.utils.address import (
|
||||
|
||||
|
||||
class Web3(object):
|
||||
# Providers
|
||||
RPCProvider = RPCProvider
|
||||
IPCProvider = IPCProvider
|
||||
TestRPCProvider = TestRPCProvider
|
||||
|
||||
# Managers
|
||||
RequestManager = RequestManager
|
||||
DelegatedSigningManager = DelegatedSigningManager
|
||||
PrivateKeySigningManager = PrivateKeySigningManager
|
||||
|
||||
# Iban
|
||||
Iban = Iban
|
||||
|
||||
@ -71,7 +81,6 @@ class Web3(object):
|
||||
|
||||
def __init__(self, provider):
|
||||
self._requestManager = RequestManager(provider)
|
||||
self.currentProvider = provider
|
||||
|
||||
self.eth = Eth(self)
|
||||
self.db = Db(self)
|
||||
@ -85,10 +94,13 @@ class Web3(object):
|
||||
|
||||
def setProvider(self, provider):
|
||||
self._requestManager.setProvider(provider)
|
||||
self.currentProvider = provider
|
||||
|
||||
def reset(self, keepIsSyncing):
|
||||
self._requestManager.reset(keepIsSyncing)
|
||||
def setManager(self, manager):
|
||||
self._requestManager = manager
|
||||
|
||||
@property
|
||||
def currentProvider(self):
|
||||
return self._requestManager.provider
|
||||
|
||||
def sha3(self, value, encoding="hex"):
|
||||
if encoding == 'hex':
|
||||
|
||||
Loading…
Reference in New Issue
Block a user