3

I have followed every option present in net to do Raw transaction I have followed

ethereumjs-tx

let resData = {};
var Tx = require('ethereumjs-tx')
var privateKey = new Buffer('0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')
var gasPrice = privateWeb3.eth.gasPrice;
var gasPriceHex = privateWeb3.toHex(gasPrice);
var nonce = privateWeb3.eth.getTransactionCount(req.body.fromAddress);
var nonceHex = privateWeb3.toHex(nonce);
var rawTx = {
    nonce: nonceHex,
    gasPrice: gasPriceHex,
    gasLimit: '0x2710000000',
    to: req.body.toAddress,
    from: req.body.fromAddress,
    data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
    chainId: req.body.chain
}

var tx = new Tx(rawTx)
console.log(tx.v);
tx.sign(privateKey)

var serializedTx = tx.serialize()
console.log(serializedTx.toString('hex'))

privateWeb3.eth.sendRawTransaction(serializedTx.toString('hex'), function(err, hash) {
    //  if (!err)
        console.log("hiii", err, hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385"
});

This approach give me error in tx.sign(privateKey)

AssertionError: The field v must have byte length of 1 at Transaction.setter [as v] (node_modules/ethereumjs-util/index.js:609:9)

3

This may be caused by unexpectedly large chainId. It is used to compute tx.v.

See EIP155:

v = CHAIN_ID * 2 + 35 or v = CHAIN_ID * 2 + 36

And ethereumjs-tx source:

// sig.v = 28

if (this._chainId > 0) {
  sig.v += this._chainId * 2 + 8
}

So, to fit v into a single byte, your chainId must be less than 0x6d (109 dec).

Ropsten has chainId = 3, mainnet has chainId = 1.

5
  • I have use ChainId 1300 as 1300 is my Network id for ethereum blockchain in private network . @max How can i get chainId for private net? Feb 28 '17 at 16:25
  • chainId can be specified in genesis.json. E.g. networkID option in parity: github.com/ethcore/parity/wiki/Chain-specification and --networkid command line option in geth. Feb 28 '17 at 16:31
  • I think @max you are right . Let me try Feb 28 '17 at 16:36
  • it is saying Error: Invalid sender at Object.InvalidResponse error . Can you point out some thing about this error. Mar 1 '17 at 5:40
  • It's hard to say. Can you please show your complete setup? Maybe it worth posting new question with your private net config and minimal reproducible code. Mar 1 '17 at 9:23
0

var privateKey = new Buffer('0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')

..you need to strip the 0x hex prefix:
new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')

ps) you can also get rid of rawTx.from.. it has no meaning and will be ignored. the raw transaction is sent "from" the address corresponding to the privateKey used to sign it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.