Skip to content

Commit df5a093

Browse files
billbsingkclowes
authored andcommitted
eth.defaultAccount to eth.default_account
1 parent a0fe3a2 commit df5a093

File tree

7 files changed

+54
-30
lines changed

7 files changed

+54
-30
lines changed

docs/contracts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ To run this example, you will need to install a few extra features:
6969
>>> w3 = Web3(Web3.EthereumTesterProvider())
7070
7171
# set pre-funded account as sender
72-
>>> w3.eth.defaultAccount = w3.eth.accounts[0]
72+
>>> w3.eth.default_account = w3.eth.accounts[0]
7373
7474
# get bytecode
7575
>>> bytecode = compiled_sol['contracts']['Greeter.sol']['Greeter']['evm']['bytecode']['object']

docs/middleware.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ Signing
402402

403403
.. py:method:: web3.middleware.construct_sign_and_send_raw_middleware(private_key_or_account)
404404
405-
This middleware automatically captures transactions, signs them, and sends them as raw transactions. The from field on the transaction, or ``w3.eth.defaultAccount`` must be set to the address of the private key for this middleware to have any effect.
405+
This middleware automatically captures transactions, signs them, and sends them as raw transactions. The from field on the transaction, or ``w3.eth.default_account`` must be set to the address of the private key for this middleware to have any effect.
406406

407407
* ``private_key_or_account`` A single private key or a tuple, list or set of private keys.
408408

@@ -420,5 +420,5 @@ This middleware automatically captures transactions, signs them, and sends them
420420
>>> from eth_account import Account
421421
>>> acct = Account.create('KEYSMASH FJAFJKLDSKF7JKFDJ 1530')
422422
>>> w3.middleware_onion.add(construct_sign_and_send_raw_middleware(acct))
423-
>>> w3.eth.defaultAccount = acct.address
423+
>>> w3.eth.default_account = acct.address
424424
# Now you can send a tx from acct.address without having to build and sign each raw transaction

docs/web3.eth.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ Properties
3838
The following properties are available on the ``web3.eth`` namespace.
3939

4040

41-
.. py:attribute:: Eth.defaultAccount
41+
.. py:attribute:: Eth.default_account
4242
4343
The ethereum address that will be used as the default ``from`` address for
4444
all transactions.
4545

46+
.. py:attribute:: Eth.defaultAccount
47+
48+
.. warning:: Deprecated: This property is deprecated in favor of
49+
:attr:`~web3.eth.default_account`
50+
4651

4752
.. py:attribute:: Eth.defaultBlock
4853

web3/contract.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,9 @@ def estimateGas(
633633
self.check_forbidden_keys_in_transaction(estimate_gas_transaction,
634634
["data", "to"])
635635

636-
if self.web3.eth.defaultAccount is not empty:
637-
# type ignored b/c check prevents an empty defaultAccount
638-
estimate_gas_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore # noqa: E501
636+
if self.web3.eth.default_account is not empty:
637+
# type ignored b/c check prevents an empty default_account
638+
estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501
639639

640640
estimate_gas_transaction['data'] = self.data_in_transaction
641641

@@ -652,9 +652,9 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
652652
self.check_forbidden_keys_in_transaction(transact_transaction,
653653
["data", "to"])
654654

655-
if self.web3.eth.defaultAccount is not empty:
656-
# type ignored b/c check prevents an empty defaultAccount
657-
transact_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
655+
if self.web3.eth.default_account is not empty:
656+
# type ignored b/c check prevents an empty default_account
657+
transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore
658658

659659
transact_transaction['data'] = self.data_in_transaction
660660

@@ -674,9 +674,9 @@ def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams:
674674
self.check_forbidden_keys_in_transaction(built_transaction,
675675
["data", "to"])
676676

677-
if self.web3.eth.defaultAccount is not empty:
678-
# type ignored b/c check prevents an empty defaultAccount
679-
built_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
677+
if self.web3.eth.default_account is not empty:
678+
# type ignored b/c check prevents an empty default_account
679+
built_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore
680680

681681
built_transaction['data'] = self.data_in_transaction
682682
built_transaction['to'] = Address(b'')
@@ -933,9 +933,9 @@ def call(
933933

934934
if self.address:
935935
call_transaction.setdefault('to', self.address)
936-
if self.web3.eth.defaultAccount is not empty:
937-
# type ignored b/c check prevents an empty defaultAccount
938-
call_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
936+
if self.web3.eth.default_account is not empty:
937+
# type ignored b/c check prevents an empty default_account
938+
call_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore
939939

940940
if 'to' not in call_transaction:
941941
if isinstance(self, type):
@@ -975,9 +975,9 @@ def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
975975

976976
if self.address is not None:
977977
transact_transaction.setdefault('to', self.address)
978-
if self.web3.eth.defaultAccount is not empty:
979-
# type ignored b/c check prevents an empty defaultAccount
980-
transact_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore
978+
if self.web3.eth.default_account is not empty:
979+
# type ignored b/c check prevents an empty default_account
980+
transact_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore
981981

982982
if 'to' not in transact_transaction:
983983
if isinstance(self, type):
@@ -1017,9 +1017,9 @@ def estimateGas(
10171017

10181018
if self.address:
10191019
estimate_gas_transaction.setdefault('to', self.address)
1020-
if self.web3.eth.defaultAccount is not empty:
1021-
# type ignored b/c check prevents an empty defaultAccount
1022-
estimate_gas_transaction.setdefault('from', self.web3.eth.defaultAccount) # type: ignore # noqa: E501
1020+
if self.web3.eth.default_account is not empty:
1021+
# type ignored b/c check prevents an empty default_account
1022+
estimate_gas_transaction.setdefault('from', self.web3.eth.default_account) # type: ignore # noqa: E501
10231023

10241024
if 'to' not in estimate_gas_transaction:
10251025
if isinstance(self, type):

web3/eth.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
class Eth(ModuleV2, Module):
106106
account = Account()
107-
defaultAccount = empty
107+
_default_account = empty
108108
defaultBlock: Literal["latest"] = "latest" # noqa: E704
109109
defaultContractFactory: Type[Union[Contract, ConciseContract, ContractCaller]] = Contract # noqa: E704,E501
110110
iban = Iban
@@ -197,6 +197,18 @@ def blockNumber(self) -> BlockNumber:
197197
def chainId(self) -> int:
198198
return self.web3.manager.request_blocking(RPC.eth_chainId, [])
199199

200+
@property
201+
def default_account(self) -> str:
202+
return self.default_account
203+
204+
@property
205+
def defaultAccount(self) -> str:
206+
warnings.warn(
207+
'defaultAccount is deprecated in favor of default_account',
208+
category=DeprecationWarning,
209+
)
210+
return self._default_account
211+
200212
def block_id_munger(
201213
self,
202214
account: Union[Address, ChecksumAddress, ENS],
@@ -371,8 +383,8 @@ def modifyTransaction(
371383

372384
def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]:
373385
# TODO: move to middleware
374-
if 'from' not in transaction and is_checksum_address(self.defaultAccount):
375-
transaction = assoc(transaction, 'from', self.defaultAccount)
386+
if 'from' not in transaction and is_checksum_address(self.default_account):
387+
transaction = assoc(transaction, 'from', self.default_account)
376388

377389
# TODO: move gas estimation in middleware
378390
if 'gas' not in transaction:
@@ -424,13 +436,14 @@ def call_munger(
424436
block_identifier: Optional[BlockIdentifier] = None
425437
) -> Tuple[TxParams, BlockIdentifier]:
426438
# TODO: move to middleware
427-
if 'from' not in transaction and is_checksum_address(self.defaultAccount):
428-
transaction = assoc(transaction, 'from', self.defaultAccount)
439+
if 'from' not in transaction and is_checksum_address(self.default_account):
440+
transaction = assoc(transaction, 'from', self.default_account)
429441

430442
# TODO: move to middleware
431443
if block_identifier is None:
432444
block_identifier = self.defaultBlock
433445

446+
<<<<<<< HEAD
434447
return (transaction, block_identifier)
435448

436449
call: Method[Callable[..., Union[bytes, bytearray]]] = Method(
@@ -445,6 +458,12 @@ def estimate_gas_munger(
445458
) -> Sequence[Union[TxParams, BlockIdentifier]]:
446459
if 'from' not in transaction and is_checksum_address(self.defaultAccount):
447460
transaction = assoc(transaction, 'from', self.defaultAccount)
461+
=======
462+
def estimateGas(self, transaction: TxParams, block_identifier: BlockIdentifier=None) -> Wei:
463+
# TODO: move to middleware
464+
if 'from' not in transaction and is_checksum_address(self.default_account):
465+
transaction = assoc(transaction, 'from', self.default_account)
466+
>>>>>>> 1b792773... eth.defaultAccount to eth.default_account
448467

449468
if block_identifier is None:
450469
params: Sequence[Union[TxParams, BlockIdentifier]] = [transaction]

web3/parity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def trace_call_munger(
161161
block_identifier: Optional[BlockIdentifier] = None
162162
) -> Tuple[TxParams, ParityTraceMode, BlockIdentifier]:
163163
# TODO: move to middleware
164-
if 'from' not in transaction and is_checksum_address(self.web3.eth.defaultAccount):
165-
transaction = assoc(transaction, 'from', self.web3.eth.defaultAccount)
164+
if 'from' not in transaction and is_checksum_address(self.web3.eth.default_account):
165+
transaction = assoc(transaction, 'from', self.web3.eth.default_account)
166166

167167
# TODO: move to middleware
168168
if block_identifier is None:

web3/pm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def release_package(
417417
) -> bytes:
418418
"""
419419
Returns the release id generated by releasing a package on the current registry.
420-
Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.defaultAccount``
420+
Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.default_account``
421421
to be the registry owner.
422422
423423
* Parameters:

0 commit comments

Comments
 (0)