Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,4 @@ Released with 1.0.0-beta.37 code base.
- lerna from 3.22.1 to 4.0.0 (#4231)
- Dropped build tests in CI for Node v8 and v10, and added support for Node v14
- Change default value for `maxPriorityFeePerGas` from `1 Gwei` to `2.5 Gwei` (#4284)
- Fixed bug in signTransaction (#4295)
6 changes: 3 additions & 3 deletions packages/web3-eth-accounts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca

var result = {
messageHash: '0x' + Buffer.from(signedTx.getMessageToSign(true)).toString('hex'),
v: '0x' + Buffer.from(signedTx.v).toString('hex'),
r: '0x' + Buffer.from(signedTx.r).toString('hex'),
s: '0x' + Buffer.from(signedTx.s).toString('hex'),
v: '0x' + signedTx.v.toString('hex'),
r: '0x' + signedTx.r.toString('hex'),
s: '0x' + signedTx.s.toString('hex'),
rawTransaction: rawTransaction,
transactionHash: transactionHash
};
Expand Down
41 changes: 40 additions & 1 deletion test/e2e.method.signing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var assert = require('assert');
var Basic = require('./sources/Basic');
var utils = require('./helpers/test.utils');
var Web3 = utils.getWeb3();
var {TransactionFactory} = require('@ethereumjs/tx');

describe('transaction and message signing [ @E2E ]', function() {
let web3;
Expand Down Expand Up @@ -563,5 +564,43 @@ describe('transaction and message signing [ @E2E ]', function() {
done(error)
}
});
});

it('accounts.signTransaction returning valid v r s values', async function(){

const source = wallet[0].address;
const destination = wallet[1].address;

const txCount = await web3.eth.getTransactionCount(source);
const networkId = await web3.eth.net.getId();
const chainId = await web3.eth.getChainId();


const customCommon = {
baseChain: 'mainnet',
customChain: {
name: 'custom-network',
networkId: networkId,
chainId: chainId,
},
hardfork: 'petersburg',
};

const txObject = {
nonce: web3.utils.toHex(txCount),
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')),
common: customCommon
};

const signed = await web3.eth.accounts.signTransaction(txObject, wallet[0].privateKey);

const data = Buffer.from(signed.rawTransaction.slice(2), "hex")
const tx = TransactionFactory.fromSerializedData(data);

assert(signed.v === ('0x' + tx.v.toString('hex')));
assert(signed.r === ('0x' + tx.r.toString('hex')));
assert(signed.s === ('0x' + tx.s.toString('hex')));
});
});