Skip to content

Replace public addresses with account variables #2594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/ens_overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Get the Address for an ENS Name

from ens.auto import ns
eth_address = ns.address('jasoncarver.eth')
assert eth_address == '0x5B2063246F2191f18F2675ceDB8b28102e957458'
assert eth_address == 'public_address'

The ``ENS`` module has no opinion as to which TLD you can use,
but will not infer a TLD if it is not provided with the name.
Expand All @@ -199,13 +199,13 @@ Get the ENS Name for an Address

.. code-block:: python

domain = ns.name('0x5B2063246F2191f18F2675ceDB8b28102e957458')
domain = ns.name('public_address')

# name() also accepts the bytes version of the address
assert ns.name(b'[ c$o!\x91\xf1\x8f&u\xce\xdb\x8b(\x10.\x95tX') == domain

# confirm that the name resolves back to the address that you looked up:
assert ns.address(domain) == '0x5B2063246F2191f18F2675ceDB8b28102e957458'
assert ns.address(domain) == 'public_address'

.. note:: For accuracy, and as a recommendation from the ENS documentation on
`reverse resolution <https://docs.ens.domains/dapp-developer-guide/resolving-names#reverse-resolution>`_,
Expand Down Expand Up @@ -233,7 +233,7 @@ you must already be the owner of the domain (or its parent).

.. code-block:: python

ns.setup_address('jasoncarver.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458')
ns.setup_address('jasoncarver.eth', 'public_address')

In the common case where you want to point the name to the owning address, you can skip the address.

Expand All @@ -250,7 +250,7 @@ You can claim arbitrarily deep subdomains.
# wait for the transaction to be mined, then:
assert (
ns.address('supreme.executive.power.derives.from.a.mandate.from.the.masses.jasoncarver.eth')
== '0x5B2063246F2191f18F2675ceDB8b28102e957458'
== 'public_address'
)

.. warning:: Gas costs scale up with the number of subdomains!
Expand All @@ -265,7 +265,7 @@ this is referred to as "reverse" resolution. The ENS Reverse Resolver is used fo

.. code-block:: python

ns.setup_name('jasoncarver.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458')
ns.setup_name('jasoncarver.eth', 'public_address')

If you don't supply the address, :meth:`~ens.ENS.setup_name` will assume you want the
address returned by :meth:`~ens.ENS.address`.
Expand All @@ -281,7 +281,7 @@ Wait for the transaction to be mined, then:

.. code-block:: python

assert ns.name('0x5B2063246F2191f18F2675ceDB8b28102e957458') == 'jasoncarver.eth'
assert ns.name('public_address') == 'jasoncarver.eth'

....

Expand All @@ -298,7 +298,7 @@ You'll need to setup the address first, and then the text can be set:

.. code-block:: python

ns.setup_address('jasoncarver.eth', '0x5B2063246F2191f18F2675ceDB8b28102e957458')
ns.setup_address('jasoncarver.eth', 'public_address')
ns.set_text('jasoncarver.eth', 'url', 'https://example.com')

A transaction dictionary can be passed as the last argument if desired:
Expand Down Expand Up @@ -336,7 +336,7 @@ You can get the resolver for an ENS name via the :meth:`~ens.ENS.resolver` metho

>>> resolver = ns.resolver('jasoncarver.eth')
>>> resolver.address
'0x5FfC014343cd971B7eb70732021E26C35B744cc4'
'resolver_address'

....

Expand Down
6 changes: 3 additions & 3 deletions docs/ethpm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Examples...

- ``ethpm://packages.zeppelinos.eth/owned@1.0.0``

- ``ethpm://0x808B53bF4D70A24bA5cb720D37A4835621A9df00:1/ethregistrar@1.0.0``
- ``ethpm://public_address:1/ethregistrar@1.0.0``

To specify a specific asset within a package, you can namespace the target asset.

Expand Down Expand Up @@ -796,7 +796,7 @@ This is the simplest builder function for adding a deployment to a manifest. All
... 'blockchain://1234567890123456789012345678901234567890123456789012345678901234/block/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef': {
... 'Owned': {
... 'contractType': 'Owned',
... 'address': '0x4F5B11C860B37B68De6d14FB7e7b5f18A9a1BD00',
... 'address': 'public_address',
... }
... }
... }
Expand All @@ -807,7 +807,7 @@ This is the simplest builder function for adding a deployment to a manifest. All
... block_uri='blockchain://1234567890123456789012345678901234567890123456789012345678901234/block/1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
... contract_instance='Owned',
... contract_type='Owned',
... address='0x4F5B11C860B37B68De6d14FB7e7b5f18A9a1BD00',
... address='public_address',
... ),
... )
>>> assert expected_manifest == built_manifest
Expand Down
36 changes: 18 additions & 18 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ representation. Block numbers
# get a block by number
>>> web3.eth.get_block(12345)
{
'author': '0xad5C1768e5974C231b2148169da064e61910f31a',
'author': 'author_address',
'difficulty': 735512610763,
'extraData': '0x476574682f76312e302e302f6c696e75782f676f312e342e32',
'gasLimit': 5000,
'gasUsed': 0,
'hash': '0x767c2bfb3bdee3f78676c1285cd757bcd5d8c272cef2eb30d9733800a78c0b6d',
'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'miner': '0xad5c1768e5974c231b2148169da064e61910f31a',
'miner': 'miner_address',
'mixHash': '0x31d9ec7e3855aeba37fd92aa1639845e70b360a60f77f12eff530429ef8cfcba',
'nonce': '0x549f882c5f356f85',
'number': 12345,
Expand Down Expand Up @@ -75,11 +75,11 @@ Checking the balance of an account

To find the amount of ether owned by an account, use the :meth:`~web3.eth.Eth.get_balance` method.
At the time of writing, the account with the `most ether <https://etherscan.io/accounts/1>`_
has a public address of 0x742d35Cc6634C0532925a3b844Bc454e4438f44e.
has a public address of public_address.

.. code-block:: python

>>> web3.eth.get_balance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e')
>>> web3.eth.get_balance('public_address')
3841357360894980500000001

Note that this number is not denominated in ether, but instead in the smallest unit of value in
Expand Down Expand Up @@ -199,7 +199,7 @@ You can look up transactions using the ``web3.eth.get_transaction`` function.
'blockNumber': 46147,
'condition': None,
'creates': None,
'from': '0xA1E4380A3B1f749673E270229993eE55F35663b4',
'from': 'from_address',
'gas': 21000,
'gasPrice': None,
'hash': '0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060',
Expand All @@ -213,7 +213,7 @@ You can look up transactions using the ``web3.eth.get_transaction`` function.
'raw': '0xf86780862d79883d2000825208945df9b87991262f6ba471f09758cde1c0fc1de734827a69801ca088ff6cf0fefd94db46111149ae4bfc179e9b94721fffd821d38d16464b3f71d0a045e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a',
's': '0x45e0aff800961cfce805daef7016b9b675c137a6a41a548f7b60a3484c06a33a',
'standardV': '0x1',
'to': '0x5DF9B87991262F6BA471F09758CDE1c0FC1De734',
'to': 'to_address',
'transactionIndex': 0,
'v': '0x1c',
'value': 31337,
Expand Down Expand Up @@ -264,7 +264,7 @@ instance, you can read data and execute transactions.
.. code-block:: python

# Configure w3, e.g., w3 = Web3(...)
address = '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F988'
address = 'public_address'
abi = '[{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"minter_","type":"address"},...'
contract_instance = w3.eth.contract(address=address, abi=abi)

Expand Down Expand Up @@ -365,7 +365,7 @@ Output:

.. code-block:: none

Deployed <stdin>:StoreVar to: 0xF2E246BB76DF876Cef8b38ae84130F4F55De395b
Deployed <stdin>:StoreVar to: public_address

Gas estimate to transact with setVar: 45535

Expand All @@ -377,7 +377,7 @@ Output:
'contractAddress': None,
'cumulativeGasUsed': 43488,
'gasUsed': 43488,
'logs': [AttributeDict({'type': 'mined', 'logIndex': 0, 'transactionIndex': 0, 'transactionHash': HexBytes('0x50aa3ba0673243f1e60f546a12ab364fc2f6603b1654052ebec2b83d4524c6d0'), 'blockHash': HexBytes('0x837609ad0a404718c131ac5157373662944b778250a507783349d4e78bd8ac84'), 'blockNumber': 2, 'address': '0xF2E246BB76DF876Cef8b38ae84130F4F55De395b', 'data': '0x', 'topics': [HexBytes('0x6c2b4666ba8da5a95717621d879a77de725f3d816709b9cbe9f059b8f875e284'), HexBytes('0x00000000000000000000000000000000000000000000000000000000000000ff')]})],
'logs': [AttributeDict({'type': 'mined', 'logIndex': 0, 'transactionIndex': 0, 'transactionHash': HexBytes('0x50aa3ba0673243f1e60f546a12ab364fc2f6603b1654052ebec2b83d4524c6d0'), 'blockHash': HexBytes('0x837609ad0a404718c131ac5157373662944b778250a507783349d4e78bd8ac84'), 'blockNumber': 2, 'address': 'public_address', 'data': '0x', 'topics': [HexBytes('0x6c2b4666ba8da5a95717621d879a77de725f3d816709b9cbe9f059b8f875e284'), HexBytes('0x00000000000000000000000000000000000000000000000000000000000000ff')]})],
'status': 1,
'transactionHash': HexBytes('0x50aa3ba0673243f1e60f546a12ab364fc2f6603b1654052ebec2b83d4524c6d0'),
'transactionIndex': 0}
Expand Down Expand Up @@ -476,12 +476,12 @@ contract which conforms to this standard.
ABI = '[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function","stateMutability":"view"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function","stateMutability":"nonpayable"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function","stateMutability":"view"},{"inputs":[{"name":"_totalSupply","type":"uint256"}],"payable":false,"type":"constructor","stateMutability":"nonpayable"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]'
factory = w3.eth.contract(abi=ABI, bytecode=bytecode)
alice, bob = w3.eth.accounts[0], w3.eth.accounts[1]
assert alice == '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf', alice
assert bob == '0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF', bob
assert alice == 'alice_public_address', alice
assert bob == 'bob_public_address', bob
tx_hash = factory.constructor(1000000).transact({'from': alice, 'gas': 899000, 'gasPrice': Web3.to_wei(1, 'gwei')})
assert tx_hash == HexBytes('0x49e3da72a95e4074a9eaea7b438c73ca154627d317e58abeae914e3769a15044'), tx_hash
txn_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
assert txn_receipt['contractAddress'] == '0xF2E246BB76DF876Cef8b38ae84130F4F55De395b', txn_receipt['contractAddress']
assert txn_receipt['contractAddress'] == 'contract_address', txn_receipt['contractAddress']
contract_address = txn_receipt['contractAddress']
contract = w3.eth.contract(contract_address, abi=ABI)
total_supply = contract.functions.totalSupply().call()
Expand All @@ -507,7 +507,7 @@ contract and the ``ERC20`` ABI.

>>> contract = w3.eth.contract(contract_address, abi=ABI)
>>> contract.address
'0xF2E246BB76DF876Cef8b38ae84130F4F55De395b'
'contract_address'


Querying token metadata
Expand Down Expand Up @@ -542,8 +542,8 @@ we'll refer to as ``alice`` holding all of the tokens.

.. doctest::

>>> alice = '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf'
>>> bob = '0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF'
>>> alice = 'alice_public_address'
>>> bob = 'bob_public_address'
>>> raw_balance = contract.functions.balanceOf(alice).call()
>>> raw_balance
1000000000000000000000000
Expand Down Expand Up @@ -785,7 +785,7 @@ Example code

The following example code is divided into a reusable ``EventScanner`` class and then a demo script that:

* fetches all transfer events for `RCC token <https://etherscan.io/token/0x9b6443b0fb9c241a7fdac375595cea13e6b7807a>`_,
* fetches all transfer events for `RCC token <https://etherscan.io/token/token_public_address>`_,

* can incrementally run again to check if there are new events,

Expand Down Expand Up @@ -1230,8 +1230,8 @@ The script can be run with: ``python ./eventscanner.py <your JSON-RPC API URL>``
from tqdm import tqdm

# RCC has around 11k Transfer events
# https://etherscan.io/token/0x9b6443b0fb9c241a7fdac375595cea13e6b7807a
RCC_ADDRESS = "0x9b6443b0fB9C241A7fdAC375595cEa13e6B7807A"
# https://etherscan.io/token/token_public_address
RCC_ADDRESS = "token_public_address"

# Reduced ERC-20 ABI, only Transfer event
ABI = """[
Expand Down
4 changes: 2 additions & 2 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ instance of the contract:
>>> tx_hash = ExampleContract.constructor().transact()
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> tx_receipt.contractAddress
'0x8a22225eD7eD460D7ee3842bce2402B9deaD23D3'
'contract_address'

Once a deployed contract is loaded into a Contract object, the functions of that
contract are available on the ``functions`` namespace:
Expand Down Expand Up @@ -323,6 +323,6 @@ ENS

`Ethereum Name Service (ENS) <https://ens.domains/>`_ provides the infrastructure
for human-readable addresses. As an example, instead of
``0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359``, you can send funds to
``public_address``, you can send funds to
``ethereumfoundation.eth``. web3.py has support for ENS, documented
:ref:`here <ens_overview>`.
4 changes: 2 additions & 2 deletions docs/web3.beacon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Methods
>>> beacon.get_spec()
{
'data': {
'DEPOSIT_CONTRACT_ADDRESS': '0x8c5fecdC472E27Bc447696F431E425D02dd46a8c',
'DEPOSIT_CONTRACT_ADDRESS': 'contract_address',
'MIN_ATTESTATION_INCLUSION_DELAY': '1',
'SLOTS_PER_EPOCH': '32',
'SHUFFLE_ROUND_COUNT': '90',
Expand All @@ -360,7 +360,7 @@ Methods
{
'data': {
'chain_id': '5',
'address': '0x8c5fecdc472e27bc447696f431e425d02dd46a8c'
'address': 'contract_address'
}
}

Expand Down
Loading