Skip to content

Commit f25d116

Browse files
committed
update eth-account to 0.5.6 and update docs
* eth-account updated to 0.5.6 * docs updated to reflect that transaction type is no longer necessary to sign transactions using web3.eth.account.sign_transaction due to recent eth-account updates * updated some more docs dealing with sign_transaction to use new dynamic fee transaction params over gasPrice
1 parent 002db29 commit f25d116

File tree

7 files changed

+47
-25
lines changed

7 files changed

+47
-25
lines changed

docs/contracts.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,13 +898,14 @@ Methods
898898

899899
.. code-block:: python
900900
901-
>>> math_contract.functions.increment(5).buildTransaction({'gasPrice': 21000000000})
901+
>>> math_contract.functions.increment(5).buildTransaction({'maxFeePerGas': 2000000000, 'maxPriorityFeePerGas': 1000000000})
902902
{
903903
'to': '0x6Bc272FCFcf89C14cebFC57B8f1543F5137F97dE',
904904
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005',
905905
'value': 0,
906906
'gas': 43242,
907-
'gasPrice': 21000000000,
907+
'maxFeePerGas': 2000000000,
908+
'maxPriorityFeePerGas': 1000000000,
908909
'chainId': 1
909910
}
910911

docs/web3.eth.account.rst

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,26 +232,41 @@ with :meth:`~web3.eth.Eth.send_raw_transaction`.
232232
... 'to': '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
233233
... 'value': 1000000000,
234234
... 'gas': 2000000,
235-
... 'gasPrice': 234567897654321,
235+
... 'maxFeePerGas': 2000000000,
236+
... 'maxPriorityFeePerGas': 1000000000,
236237
... 'nonce': 0,
237-
... 'chainId': 1
238+
... 'chainId': 1,
239+
... 'type': '0x2', # type is optional and will be implicitly decided based on the transaction parameters
240+
... 'accessList': ( # accessList is optional for dynamic fee transactions
241+
... {
242+
... 'address': '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
243+
... 'storageKeys': (
244+
... '0x0000000000000000000000000000000000000000000000000000000000000003',
245+
... '0x0000000000000000000000000000000000000000000000000000000000000007',
246+
... )
247+
... },
248+
... {
249+
... 'address': '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
250+
... 'storageKeys': ()
251+
... },
252+
... )
238253
... }
239254
>>> key = '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
240255
>>> signed = w3.eth.account.sign_transaction(transaction, key)
241256
>>> signed.rawTransaction
242-
HexBytes('0xf86a8086d55698372431831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008025a009ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9ca0440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428')
257+
HexBytes('0x02f8e20180843b9aca008477359400831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca0080f872f85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000007d694bb9bc244d798123fde783fcc1c72d3bb8c189413c001a0b9ec671ccee417ff79e06e9e52bfa82b37cf1145affde486006072ca7a11cf8da0484a9beea46ff6a90ac76e7bbf3718db16a8b4b09cef477fb86cf4e123d98fde')
243258
>>> signed.hash
244-
HexBytes('0xd8f64a42b57be0d565f385378db2f6bf324ce14a594afc05de90436e9ce01f60')
259+
HexBytes('0xe85ce7efa52c16cb5c469c7bde54fbd4911639fdfde08003f65525a85076d915')
245260
>>> signed.r
246-
4487286261793418179817841024889747115779324305375823110249149479905075174044
261+
84095564551732371065849105252408326384410939276686534847013731510862163857293
247262
>>> signed.s
248-
30785525769477805655994251009256770582792548537338581640010273753578382951464
263+
32698347985257114675470251181312399332782188326270244072370350491677872459742
249264
>>> signed.v
250-
37
265+
1
251266

252267
# When you run send_raw_transaction, you get back the hash of the transaction:
253268
>>> w3.eth.send_raw_transaction(signed.rawTransaction) # doctest: +SKIP
254-
'0xd8f64a42b57be0d565f385378db2f6bf324ce14a594afc05de90436e9ce01f60'
269+
'0xe85ce7efa52c16cb5c469c7bde54fbd4911639fdfde08003f65525a85076d915'
255270

256271
Sign a Contract Transaction
257272
-----------------------------------
@@ -291,34 +306,37 @@ To sign a transaction locally that will invoke a smart contract:
291306
... ).buildTransaction({
292307
... 'chainId': 1,
293308
... 'gas': 70000,
294-
... 'gasPrice': w3.toWei('1', 'gwei'),
309+
... 'maxFeePerGas': w3.toWei('2', 'gwei'),
310+
... 'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
295311
... 'nonce': nonce,
296312
... })
297313

298314
>>> unicorn_txn
299315
{'value': 0,
316+
'type': '0x2',
300317
'chainId': 1,
301318
'gas': 70000,
302-
'gasPrice': 1000000000,
319+
'maxFeePerGas': 2000000000,
320+
'maxPriorityFeePerGas': 1000000000,
303321
'nonce': 0,
304322
'to': '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
305323
'data': '0xa9059cbb000000000000000000000000fb6916095ca1df60bb79ce92ce3ea74c37c5d3590000000000000000000000000000000000000000000000000000000000000001'}
306324

307325
>>> private_key = b"\xb2\\}\xb3\x1f\xee\xd9\x12''\xbf\t9\xdcv\x9a\x96VK-\xe4\xc4rm\x03[6\xec\xf1\xe5\xb3d"
308326
>>> signed_txn = w3.eth.account.sign_transaction(unicorn_txn, private_key=private_key)
309327
>>> signed_txn.hash
310-
HexBytes('0x4795adc6a719fa64fa21822630c0218c04996e2689ded114b6553cef1ae36618')
328+
HexBytes('0x748db062639a45e519dba934fce09c367c92043867409160c9989673439dc817')
311329
>>> signed_txn.rawTransaction
312-
HexBytes('0xf8a980843b9aca008301117094fb6916095ca1df60bb79ce92ce3ea74c37c5d35980b844a9059cbb000000000000000000000000fb6916095ca1df60bb79ce92ce3ea74c37c5d359000000000000000000000000000000000000000000000000000000000000000125a00fb532eea06b8f17d858d82ad61986efd0647124406be65d359e96cac3e004f0a02e5d7ffcfb7a6073a723be38e6733f353cf9367743ae94e2ccd6f1eba37116f4')
330+
HexBytes('0x02f8b00180843b9aca0084773594008301117094fb6916095ca1df60bb79ce92ce3ea74c37c5d35980b844a9059cbb000000000000000000000000fb6916095ca1df60bb79ce92ce3ea74c37c5d3590000000000000000000000000000000000000000000000000000000000000001c001a0cec4150e52898cf1295cc4020ac0316cbf186071e7cdc5ec44eeb7cdda05afa2a06b0b3a09c7fb0112123c0bef1fd6334853a9dcf3cb5bab3ccd1f5baae926d449')
313331
>>> signed_txn.r
314-
7104843568152743554992057394334744036860247658813231830421570918634460546288
332+
93522894155654168208483453926995743737629589441154283159505514235904280342434
315333
>>> signed_txn.s
316-
20971591154030974221209741174186570949918731455961098911091818811306894497524
334+
48417310681110102814014302147799665717176259465062324746227758019974374282313
317335
>>> signed_txn.v
318-
37
336+
1
319337

320338
>>> w3.eth.send_raw_transaction(signed_txn.rawTransaction) # doctest: +SKIP
321339

322340
# When you run send_raw_transaction, you get the same result as the hash of the transaction:
323341
>>> w3.toHex(w3.keccak(signed_txn.rawTransaction))
324-
'0x4795adc6a719fa64fa21822630c0218c04996e2689ded114b6553cef1ae36618'
342+
'0x748db062639a45e519dba934fce09c367c92043867409160c9989673439dc817'

docs/web3.eth.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ The following methods are available on the ``web3.eth`` namespace.
839839
840840
>>> signed_txn = w3.eth.sign_transaction(dict(
841841
nonce=w3.eth.get_transaction_count(w3.eth.coinbase),
842-
gasPrice=w3.eth.gas_price,
842+
maxFeePerGas=2000000000,
843+
maxPriorityFeePerGas=1000000000,
843844
gas=100000,
844845
to='0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
845846
value=1,
@@ -870,7 +871,7 @@ The following methods are available on the ``web3.eth`` namespace.
870871
to='0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
871872
value=12345,
872873
data=b'',
873-
type=2,
874+
type=2, # (optional) the type is now implicitly set based on appropriate transaction params
874875
chainId=1,
875876
),
876877
private_key_for_senders_account,

newsfragments/2157.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated docs for w3.eth.account.sign_transaction to reflect that transaction type is no longer needed to successfully sign typed transactions and to illustrate how to structure an optional accessList parameter in a typed transaction

newsfragments/2157.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated eth-account version to v0.5.6 - adds support for signing typed transactions without needing to explicitly set the transaction type and now accepts correct JSON-RPC structure for accessList for typed transactions

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
install_requires=[
7575
"aiohttp>=3.7.4.post0,<4",
7676
"eth-abi>=2.0.0b6,<3.0.0",
77-
"eth-account>=0.5.5,<0.6.0",
77+
"eth-account>=0.5.6,<0.6.0",
7878
"eth-hash[pycryptodome]>=0.2.0,<1.0.0",
7979
"eth-typing>=2.0.0,<3.0.0",
8080
"eth-utils>=1.9.5,<2.0.0",

tests/core/eth-module/test_accounts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ def test_eth_account_sign(acct,
301301
"value": "0x5af3107a4000",
302302
"type": "0x2",
303303
"accessList": (
304-
(
305-
"0x0000000000000000000000000000000000000001",
306-
(
304+
{
305+
"address": "0x0000000000000000000000000000000000000001",
306+
"storageKeys": (
307307
"0x0100000000000000000000000000000000000000000000000000000000000000",
308308
),
309-
),
309+
},
310310
),
311311
"chainId": 1,
312312
},

0 commit comments

Comments
 (0)