Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit a2027aa

Browse files
authored
eth.accounts.signTransaction method fixed (#3141)
* signTransaction updated, getId method in net module, and e2e signTransaction method updated * types and documentation for accounts.signTransaction updated * example for custom common added * CHANGELOG.md updated and url added to accounts.signTransaction documentation * error msg improved * web3-eth sendTransaction documentation updated * parameter validation updated for accounts.signTransaction method * Auto fetch tx signing option values when not set by user (#3143) * public api simplified if someone wants to pass custom chain configuration (ethereumjs-common) * default properties added (chain, hardfork, and common) and related types updated * documentation updated for new default properties * typo fixed in docs and conditions for the new default properties updated in the Method class of the web3-core-method module * funcDocs fixed in utils and missing option properties added in the web3-eth-contract module
1 parent cf96133 commit a2027aa

File tree

26 files changed

+904
-346
lines changed

26 files changed

+904
-346
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Released with 1.0.0-beta.37 code base.
5858
- Add `eth.getChainId` method (#3113)
5959
- Minified file added to web3 package (#3131)
6060
- The transaction confirmation workflow can now be configured (#3130)
61+
- Additional parameters for accounts.signTransaction added [(docs)](https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#signtransaction) (#3141)
6162
- Emit `connected` event on subscription creation (#3028)
6263
- TypeScript type definitions added for all modules (#3132)
6364
- Bloom filters added to web3.utils (#3137)

docs/web3-eth-accounts.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ Parameters
150150
- ``value`` - ``String``: (optional) The value of the transaction in wei.
151151
- ``gasPrice`` - ``String``: (optional) The gas price set by this transaction, if empty, it will use :ref:`web3.eth.gasPrice() <eth-gasprice>`
152152
- ``gas`` - ``String``: The gas provided by the transaction.
153+
- ``chain`` - ``String``: (optional) Defaults to ``mainnet``.
154+
- ``hardfork`` - ``String``: (optional) Defaults to ``petersburg``.
155+
- ``common`` - ``Object``: (optional) The common object
156+
- ``customChain`` - ``Object``: The custom chain properties
157+
- ``name`` - ``string``: (optional) The name of the chain
158+
- ``networkId`` - ``number``: Network ID of the custom chain
159+
- ``chainId`` - ``number``: Chain ID of the custom chain
160+
- ``baseChain`` - ``string``: (optional) ``mainnet``, ``goerli``, ``kovan``, ``rinkeby``, or ``ropsten``
161+
- ``hardfork`` - ``string``: (optional) ``chainstart``, ``homestead``, ``dao``, ``tangerineWhistle``, ``spuriousDragon``, ``byzantium``, ``constantinople``, ``petersburg``, or ``istanbul``
153162
2. ``privateKey`` - ``String``: The private key to sign with.
154163
3. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second.
155164

@@ -206,6 +215,24 @@ Example
206215
transactionHash: '0xd8f64a42b57be0d565f385378db2f6bf324ce14a594afc05de90436e9ce01f60'
207216
}
208217
218+
// or with a common
219+
web3.eth.accounts.signTransaction({
220+
to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
221+
value: '1000000000',
222+
gas: 2000000
223+
common: {
224+
baseChain: 'mainnet',
225+
hardfork: 'petersburg',
226+
customChain: {
227+
name: 'custom-chain',
228+
chainId: 1,
229+
networkId: 1
230+
}
231+
}
232+
}, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318')
233+
.then(console.log);
234+
235+
209236
210237
211238
------------------------------------------------------------------------------

docs/web3-eth-contract.rst

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Property
138138
----------
139139

140140

141-
Default block parameters can be one of the following:
141+
The default block parameters can be one of the following:
142142

143143
- ``Number``: A block number
144144
- ``"genesis"`` - ``String``: The genesis block
@@ -161,6 +161,139 @@ Example
161161
contract.defaultBlock = 231;
162162
163163
164+
165+
------------------------------------------------------------------------------
166+
167+
.. _eth-contract-defaulthardfork:
168+
169+
defaultHardfork
170+
=====================
171+
172+
.. code-block:: javascript
173+
174+
contract.defaultHardfork
175+
176+
The default hardfork property is used for signing transactions locally.
177+
178+
----------
179+
Property
180+
----------
181+
182+
183+
The default hardfork property can be one of the following:
184+
185+
- ``"chainstart"`` - ``String``
186+
- ``"homestead"`` - ``String``
187+
- ``"dao"`` - ``String``
188+
- ``"tangerineWhistle"`` - ``String``
189+
- ``"spuriousDragon"`` - ``String``
190+
- ``"byzantium"`` - ``String``
191+
- ``"constantinople"`` - ``String``
192+
- ``"petersburg"`` - ``String``
193+
- ``"istanbul"`` - ``String``
194+
195+
Default is ``"petersburg"``
196+
197+
198+
-------
199+
Example
200+
-------
201+
202+
.. code-block:: javascript
203+
204+
contract.defaultHardfork;
205+
> "petersburg"
206+
207+
// set the default block
208+
contract.defaultHardfork = 'istanbul';
209+
210+
211+
------------------------------------------------------------------------------
212+
213+
.. _eth-contract-defaultchain:
214+
215+
defaultChain
216+
=====================
217+
218+
.. code-block:: javascript
219+
220+
contract.defaultChain
221+
222+
The default chain property is used for signing transactions locally.
223+
224+
----------
225+
Property
226+
----------
227+
228+
229+
The default chain property can be one of the following:
230+
231+
- ``"mainnet"`` - ``String``
232+
- ``"goerli"`` - ``String``
233+
- ``"kovan"`` - ``String``
234+
- ``"rinkeby"`` - ``String``
235+
- ``"ropsten"`` - ``String``
236+
237+
Default is ``"mainnet"``
238+
239+
240+
-------
241+
Example
242+
-------
243+
244+
.. code-block:: javascript
245+
246+
contract.defaultChain;
247+
> "mainnet"
248+
249+
// set the default chain
250+
contract.defaultChain = 'goerli';
251+
252+
253+
------------------------------------------------------------------------------
254+
255+
.. _eth-contract-defaultcommon:
256+
257+
defaultCommon
258+
=====================
259+
260+
.. code-block:: javascript
261+
262+
contract.defaultCommon
263+
264+
The default common property is used for signing transactions locally.
265+
266+
----------
267+
Property
268+
----------
269+
270+
271+
The default common property does contain the following ``Common`` object:
272+
273+
- ``customChain`` - ``Object``: The custom chain properties
274+
- ``name`` - ``string``: (optional) The name of the chain
275+
- ``networkId`` - ``number``: Network ID of the custom chain
276+
- ``chainId`` - ``number``: Chain ID of the custom chain
277+
- ``baseChain`` - ``string``: (optional) ``mainnet``, ``goerli``, ``kovan``, ``rinkeby``, or ``ropsten``
278+
- ``hardfork`` - ``string``: (optional) ``chainstart``, ``homestead``, ``dao``, ``tangerineWhistle``, ``spuriousDragon``, ``byzantium``, ``constantinople``, ``petersburg``, or ``istanbul``
279+
280+
281+
Default is ``undefined``.
282+
283+
284+
-------
285+
Example
286+
-------
287+
288+
.. code-block:: javascript
289+
290+
contract.defaultCommon;
291+
> {customChain: {name: 'custom-network', chainId: 1, networkId: 1}, baseChain: 'mainnet', hardfork: 'petersburg'}
292+
293+
// set the default common
294+
contract.defaultCommon = {customChain: {name: 'custom-network', chainId: 1, networkId: 1}, baseChain: 'mainnet', hardfork: 'petersburg'};
295+
296+
164297
------------------------------------------------------------------------------
165298

166299
.. _eth-contract-transactionblocktimeout:

docs/web3-eth.rst

Lines changed: 148 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,135 @@ Example
208208
web3.eth.defaultBlock = 231;
209209
210210
211+
------------------------------------------------------------------------------
212+
.. _eth-defaulthardfork:
213+
214+
defaultHardfork
215+
=====================
216+
217+
.. code-block:: javascript
218+
219+
web3.eth.defaultHardfork
220+
221+
The default hardfork property is used for signing transactions locally.
222+
223+
----------
224+
Property
225+
----------
226+
227+
228+
The default hardfork property can be one of the following:
229+
230+
- ``"chainstart"`` - ``String``
231+
- ``"homestead"`` - ``String``
232+
- ``"dao"`` - ``String``
233+
- ``"tangerineWhistle"`` - ``String``
234+
- ``"spuriousDragon"`` - ``String``
235+
- ``"byzantium"`` - ``String``
236+
- ``"constantinople"`` - ``String``
237+
- ``"petersburg"`` - ``String``
238+
- ``"istanbul"`` - ``String``
239+
240+
Default is ``"petersburg"``
241+
242+
243+
-------
244+
Example
245+
-------
246+
247+
.. code-block:: javascript
248+
249+
web3.eth.defaultHardfork;
250+
> "petersburg"
251+
252+
// set the default block
253+
web3.eth.defaultHardfork = 'istanbul';
254+
255+
256+
------------------------------------------------------------------------------
257+
.. _eth-defaultchain:
258+
259+
defaultChain
260+
=====================
261+
262+
.. code-block:: javascript
263+
264+
web3.eth.defaultChain
265+
266+
The default chain property is used for signing transactions locally.
267+
268+
----------
269+
Property
270+
----------
271+
272+
273+
The default chain property can be one of the following:
274+
275+
- ``"mainnet"`` - ``String``
276+
- ``"goerli"`` - ``String``
277+
- ``"kovan"`` - ``String``
278+
- ``"rinkeby"`` - ``String``
279+
- ``"ropsten"`` - ``String``
280+
281+
Default is ``"mainnet"``
282+
283+
284+
-------
285+
Example
286+
-------
287+
288+
.. code-block:: javascript
289+
290+
web3.eth.defaultChain;
291+
> "mainnet"
292+
293+
// set the default chain
294+
web3.eth.defaultChain = 'goerli';
295+
296+
297+
------------------------------------------------------------------------------
298+
.. _eth-defaultcommon:
299+
300+
defaultCommon
301+
=====================
302+
303+
.. code-block:: javascript
304+
305+
web3.eth.defaultCommon
306+
307+
The default common property is used for signing transactions locally.
308+
309+
----------
310+
Property
311+
----------
312+
313+
314+
The default common property does contain the following ``Common`` object:
315+
316+
- ``customChain`` - ``Object``: The custom chain properties
317+
- ``name`` - ``string``: (optional) The name of the chain
318+
- ``networkId`` - ``number``: Network ID of the custom chain
319+
- ``chainId`` - ``number``: Chain ID of the custom chain
320+
- ``baseChain`` - ``string``: (optional) ``mainnet``, ``goerli``, ``kovan``, ``rinkeby``, or ``ropsten``
321+
- ``hardfork`` - ``string``: (optional) ``chainstart``, ``homestead``, ``dao``, ``tangerineWhistle``, ``spuriousDragon``, ``byzantium``, ``constantinople``, ``petersburg``, or ``istanbul``
322+
323+
324+
Default is ``undefined``.
325+
326+
327+
-------
328+
Example
329+
-------
330+
331+
.. code-block:: javascript
332+
333+
web3.eth.defaultCommon;
334+
> {customChain: {name: 'custom-network', chainId: 1, networkId: 1}, baseChain: 'mainnet', hardfork: 'petersburg'}
335+
336+
// set the default common
337+
web3.eth.defaultCommon = {customChain: {name: 'custom-network', chainId: 1, networkId: 1}, baseChain: 'mainnet', hardfork: 'petersburg'};
338+
339+
211340
------------------------------------------------------------------------------
212341

213342
.. _web3-module-transactionblocktimeout:
@@ -1049,16 +1178,27 @@ Parameters
10491178

10501179

10511180
1. ``Object`` - The transaction object to send:
1052-
- ``from`` - ``String|Number``: The address for the sending account. Uses the :ref:`web3.eth.defaultAccount <eth-defaultaccount>` property, if not specified. Or an address or index of a local wallet in :ref:`web3.eth.accounts.wallet <eth_accounts_wallet>`.
1053-
- ``to`` - ``String``: (optional) The destination address of the message, left undefined for a contract-creation transaction.
1054-
- ``value`` - ``Number|String|BN|BigNumber``: (optional) The value transferred for the transaction in :ref:`wei <what-is-wei>`, also the endowment if it's a contract-creation transaction.
1055-
- ``gas`` - ``Number``: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).
1056-
- ``gasPrice`` - ``Number|String|BN|BigNumber``: (optional) The price of gas for this transaction in :ref:`wei <what-is-wei>`, defaults to :ref:`web3.eth.gasPrice <eth-gasprice>`.
1057-
- ``data`` - ``String``: (optional) Either a `ABI byte string <http://solidity.readthedocs.io/en/latest/abi-spec.html>`_ containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code.
1058-
- ``nonce`` - ``Number``: (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
1181+
- ``from`` - ``String|Number``: The address for the sending account. Uses the :ref:`web3.eth.defaultAccount <eth-defaultaccount>` property, if not specified. Or an address or index of a local wallet in :ref:`web3.eth.accounts.wallet <eth_accounts_wallet>`.
1182+
- ``to`` - ``String``: (optional) The destination address of the message, left undefined for a contract-creation transaction.
1183+
- ``value`` - ``Number|String|BN|BigNumber``: (optional) The value transferred for the transaction in :ref:`wei <what-is-wei>`, also the endowment if it's a contract-creation transaction.
1184+
- ``gas`` - ``Number``: (optional, default: To-Be-Determined) The amount of gas to use for the transaction (unused gas is refunded).
1185+
- ``gasPrice`` - ``Number|String|BN|BigNumber``: (optional) The price of gas for this transaction in :ref:`wei <what-is-wei>`, defaults to :ref:`web3.eth.gasPrice <eth-gasprice>`.
1186+
- ``data`` - ``String``: (optional) Either a `ABI byte string <http://solidity.readthedocs.io/en/latest/abi-spec.html>`_ containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code.
1187+
- ``nonce`` - ``Number``: (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
1188+
- ``chain`` - ``String``: (optional) Defaults to ``mainnet``.
1189+
- ``hardfork`` - ``String``: (optional) Defaults to ``petersburg``.
1190+
- ``common`` - ``Object``: (optional) The common object
1191+
- ``customChain`` - ``Object``: The custom chain properties
1192+
- ``name`` - ``string``: (optional) The name of the chain
1193+
- ``networkId`` - ``number``: Network ID of the custom chain
1194+
- ``chainId`` - ``number``: Chain ID of the custom chain
1195+
- ``baseChain`` - ``string``: (optional) ``mainnet``, ``goerli``, ``kovan``, ``rinkeby``, or ``ropsten``
1196+
- ``hardfork`` - ``string``: (optional) ``chainstart``, ``homestead``, ``dao``, ``tangerineWhistle``, ``spuriousDragon``, ``byzantium``, ``constantinople``, ``petersburg``, or ``istanbul``
1197+
10591198
2. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second.
10601199

1061-
.. note:: The ``from`` property can also be an address or index from the :ref:`web3.eth.accounts.wallet <eth_accounts_wallet>`. It will then sign locally using the private key of that account, and send the transaction via :ref:`web3.eth.sendSignedTransaction() <eth-sendsignedtransaction>`.
1200+
.. note:: The ``from`` property can also be an address or index from the :ref:`web3.eth.accounts.wallet <eth_accounts_wallet>`. It will then sign locally using the private key of that account, and send the transaction via :ref:`web3.eth.sendSignedTransaction() <eth-sendsignedtransaction>`. If the properties ``chain`` and ``hardfork`` or ``common`` are not set, Web3 will try to set appropriate values by
1201+
querying the network for its chainId and networkId.
10621202

10631203
.. _eth-sendtransaction-return:
10641204

0 commit comments

Comments
 (0)