diff --git a/CHANGELOG.md b/CHANGELOG.md index 0531f775e08..a9abbc7e757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -105,7 +105,7 @@ Released with 1.0.0-beta.37 code base. - ``eth_requestAccounts`` as ``requestAccounts`` added to web3-eth package (#3219) - ``sha3Raw`` and ``soliditySha3Raw`` added to web3-utils package (#3226) - ``eth_getProof`` as ``getProof`` added to web3-eth package (#3220) -- ``BN`` and ``BigNumber`` objects are now supported by the ``abi.encodeParameter(s)`` method (#3238) +- ``BN`` and ``BigNumber`` objects are now supported by the ``abi.encodeParameter(s)`` method (#3238) - ``getPendingTransactions`` added to web3-eth package (#3239) - Revert instruction handling added which can get activated with the ``handleRevert`` module property (#3248) - The ``receipt`` does now exist as property on the error object for transaction related errors (#3259) @@ -117,8 +117,9 @@ Released with 1.0.0-beta.37 code base. ### Fixed +- Fix user supplied callback not fired in eth.accounts.signTransaction (#3283) - Fix minified bundle (#3256) - ``defaultBlock`` property handling fixed (#3247) -- ``clearSubscriptions`` does no longer throw an error if no running subscriptions do exist (#3246) +- ``clearSubscriptions`` does no longer throw an error if no running subscriptions do exist (#3246) - callback type definition for ``Accounts.signTransaction`` fixed (#3280) - fix: export bloom functions on the index.js diff --git a/packages/web3-eth-accounts/src/index.js b/packages/web3-eth-accounts/src/index.js index ca73e7bffab..41400cef16b 100644 --- a/packages/web3-eth-accounts/src/index.js +++ b/packages/web3-eth-accounts/src/index.js @@ -128,7 +128,6 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca var _this = this, error = false, transactionOptions = {}, - result, hasTxSigningOptions = !!(tx && ((tx.chain && tx.hardfork) || tx.common)); callback = callback || function() { @@ -235,7 +234,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca var rawTransaction = '0x' + rlpEncoded; var transactionHash = utils.keccak256(rawTransaction); - return { + var result = { messageHash: '0x' + Buffer.from(ethTx.hash(false)).toString('hex'), v: '0x' + Buffer.from(ethTx.v).toString('hex'), r: '0x' + Buffer.from(ethTx.r).toString('hex'), @@ -244,13 +243,13 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca transactionHash: transactionHash }; + callback(null, result); + return result; + } catch (e) { callback(e); return Promise.reject(e); } - - callback(null, result); - return result; } diff --git a/test/e2e.method.signing.js b/test/e2e.method.signing.js index 5631de6c800..3ca58762705 100644 --- a/test/e2e.method.signing.js +++ b/test/e2e.method.signing.js @@ -113,6 +113,24 @@ describe('transaction and message signing [ @E2E ]', function() { assert(receipt.status === true); }); + it('accounts.signTransaction, (with callback, nonce not specified)', function(done){ + const source = wallet[0].address; + const destination = wallet[1].address; + + const txObject = { + to: destination, + value: web3.utils.toHex(web3.utils.toWei('0.1', 'ether')), + gasLimit: web3.utils.toHex(21000), + gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')), + }; + + web3.eth.accounts.signTransaction(txObject, wallet[0].privateKey, async function(err, signed){ + const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction); + assert(receipt.status === true); + done(); + }); + }); + it('accounts.signTransaction errors when common, chain and hardfork all defined', async function(){ const source = wallet[0].address; const destination = wallet[1].address;