Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update eth-account to 0.5.6 and update docs
Browse files Browse the repository at this point in the history
* 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
fselmo committed Sep 24, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
coreyja Corey Alexander
1 parent 002db29 commit 514448d
Showing 7 changed files with 47 additions and 25 deletions.
5 changes: 3 additions & 2 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
@@ -898,13 +898,14 @@ Methods

.. code-block:: python
>>> math_contract.functions.increment(5).buildTransaction({'gasPrice': 21000000000})
>>> math_contract.functions.increment(5).buildTransaction({'maxFeePerGas': 2000000000, 'maxPriorityFeePerGas': 1000000000})
{
'to': '0x6Bc272FCFcf89C14cebFC57B8f1543F5137F97dE',
'data': '0x7cf5dab00000000000000000000000000000000000000000000000000000000000000005',
'value': 0,
'gas': 43242,
'gasPrice': 21000000000,
'maxFeePerGas': 2000000000,
'maxPriorityFeePerGas': 1000000000,
'chainId': 1
}
50 changes: 34 additions & 16 deletions docs/web3.eth.account.rst
Original file line number Diff line number Diff line change
@@ -232,26 +232,41 @@ with :meth:`~web3.eth.Eth.send_raw_transaction`.
... 'to': '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
... 'value': 1000000000,
... 'gas': 2000000,
... 'gasPrice': 234567897654321,
... 'maxFeePerGas': 2000000000,
... 'maxPriorityFeePerGas': 1000000000,
... 'nonce': 0,
... 'chainId': 1
... 'chainId': 1,
... 'type': '0x2', # the type is optional and, if omitted, will be interpreted based on the provided transaction parameters
... 'accessList': ( # accessList is optional for dynamic fee transactions
... {
... 'address': '0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae',
... 'storageKeys': (
... '0x0000000000000000000000000000000000000000000000000000000000000003',
... '0x0000000000000000000000000000000000000000000000000000000000000007',
... )
... },
... {
... 'address': '0xbb9bc244d798123fde783fcc1c72d3bb8c189413',
... 'storageKeys': ()
... },
... )
... }
>>> key = '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
>>> signed = w3.eth.account.sign_transaction(transaction, key)
>>> signed.rawTransaction
HexBytes('0xf86a8086d55698372431831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008025a009ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9ca0440ffd775ce91a833ab410777204d5341a6f9fa91216a6f3ee2c051fea6a0428')
HexBytes('0x02f8e20180843b9aca008477359400831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca0080f872f85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000007d694bb9bc244d798123fde783fcc1c72d3bb8c189413c001a0b9ec671ccee417ff79e06e9e52bfa82b37cf1145affde486006072ca7a11cf8da0484a9beea46ff6a90ac76e7bbf3718db16a8b4b09cef477fb86cf4e123d98fde')
>>> signed.hash
HexBytes('0xd8f64a42b57be0d565f385378db2f6bf324ce14a594afc05de90436e9ce01f60')
HexBytes('0xe85ce7efa52c16cb5c469c7bde54fbd4911639fdfde08003f65525a85076d915')
>>> signed.r
4487286261793418179817841024889747115779324305375823110249149479905075174044
84095564551732371065849105252408326384410939276686534847013731510862163857293
>>> signed.s
30785525769477805655994251009256770582792548537338581640010273753578382951464
32698347985257114675470251181312399332782188326270244072370350491677872459742
>>> signed.v
37
1

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

Sign a Contract Transaction
-----------------------------------
@@ -291,34 +306,37 @@ To sign a transaction locally that will invoke a smart contract:
... ).buildTransaction({
... 'chainId': 1,
... 'gas': 70000,
... 'gasPrice': w3.toWei('1', 'gwei'),
... 'maxFeePerGas': w3.toWei('2', 'gwei'),
... 'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
... 'nonce': nonce,
... })

>>> unicorn_txn
{'value': 0,
'type': '0x2',
'chainId': 1,
'gas': 70000,
'gasPrice': 1000000000,
'maxFeePerGas': 2000000000,
'maxPriorityFeePerGas': 1000000000,
'nonce': 0,
'to': '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
'data': '0xa9059cbb000000000000000000000000fb6916095ca1df60bb79ce92ce3ea74c37c5d3590000000000000000000000000000000000000000000000000000000000000001'}

>>> private_key = b"\xb2\\}\xb3\x1f\xee\xd9\x12''\xbf\t9\xdcv\x9a\x96VK-\xe4\xc4rm\x03[6\xec\xf1\xe5\xb3d"
>>> signed_txn = w3.eth.account.sign_transaction(unicorn_txn, private_key=private_key)
>>> signed_txn.hash
HexBytes('0x4795adc6a719fa64fa21822630c0218c04996e2689ded114b6553cef1ae36618')
HexBytes('0x748db062639a45e519dba934fce09c367c92043867409160c9989673439dc817')
>>> signed_txn.rawTransaction
HexBytes('0xf8a980843b9aca008301117094fb6916095ca1df60bb79ce92ce3ea74c37c5d35980b844a9059cbb000000000000000000000000fb6916095ca1df60bb79ce92ce3ea74c37c5d359000000000000000000000000000000000000000000000000000000000000000125a00fb532eea06b8f17d858d82ad61986efd0647124406be65d359e96cac3e004f0a02e5d7ffcfb7a6073a723be38e6733f353cf9367743ae94e2ccd6f1eba37116f4')
HexBytes('0x02f8b00180843b9aca0084773594008301117094fb6916095ca1df60bb79ce92ce3ea74c37c5d35980b844a9059cbb000000000000000000000000fb6916095ca1df60bb79ce92ce3ea74c37c5d3590000000000000000000000000000000000000000000000000000000000000001c001a0cec4150e52898cf1295cc4020ac0316cbf186071e7cdc5ec44eeb7cdda05afa2a06b0b3a09c7fb0112123c0bef1fd6334853a9dcf3cb5bab3ccd1f5baae926d449')
>>> signed_txn.r
7104843568152743554992057394334744036860247658813231830421570918634460546288
93522894155654168208483453926995743737629589441154283159505514235904280342434
>>> signed_txn.s
20971591154030974221209741174186570949918731455961098911091818811306894497524
48417310681110102814014302147799665717176259465062324746227758019974374282313
>>> signed_txn.v
37
1

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

# When you run send_raw_transaction, you get the same result as the hash of the transaction:
>>> w3.toHex(w3.keccak(signed_txn.rawTransaction))
'0x4795adc6a719fa64fa21822630c0218c04996e2689ded114b6553cef1ae36618'
'0x748db062639a45e519dba934fce09c367c92043867409160c9989673439dc817'
5 changes: 3 additions & 2 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
@@ -839,7 +839,8 @@ The following methods are available on the ``web3.eth`` namespace.
>>> signed_txn = w3.eth.sign_transaction(dict(
nonce=w3.eth.get_transaction_count(w3.eth.coinbase),
gasPrice=w3.eth.gas_price,
maxFeePerGas=2000000000,
maxPriorityFeePerGas=1000000000,
gas=100000,
to='0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
value=1,
@@ -870,7 +871,7 @@ The following methods are available on the ``web3.eth`` namespace.
to='0xd3CdA913deB6f67967B99D67aCDFa1712C293601',
value=12345,
data=b'',
type=2,
type=2, # (optional) the type is now implicitly set based on appropriate transaction params
chainId=1,
),
private_key_for_senders_account,
1 change: 1 addition & 0 deletions newsfragments/2157.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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
1 change: 1 addition & 0 deletions newsfragments/2157.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@
install_requires=[
"aiohttp>=3.7.4.post0,<4",
"eth-abi>=2.0.0b6,<3.0.0",
"eth-account>=0.5.5,<0.6.0",
"eth-account>=0.5.6,<0.6.0",
"eth-hash[pycryptodome]>=0.2.0,<1.0.0",
"eth-typing>=2.0.0,<3.0.0",
"eth-utils>=1.9.5,<2.0.0",
8 changes: 4 additions & 4 deletions tests/core/eth-module/test_accounts.py
Original file line number Diff line number Diff line change
@@ -301,12 +301,12 @@ def test_eth_account_sign(acct,
"value": "0x5af3107a4000",
"type": "0x2",
"accessList": (
(
"0x0000000000000000000000000000000000000001",
(
{
"address": "0x0000000000000000000000000000000000000001",
"storageKeys": (
"0x0100000000000000000000000000000000000000000000000000000000000000",
),
),
},
),
"chainId": 1,
},

0 comments on commit 514448d

Please sign in to comment.