Ethereum Transactions – Creating and Signing Offline Raw Transactions

json-rpcofflineraw-transactionsignaturetransactions

I'm looking to create a raw transaction, sign it, and broadcast it using the eth.sendRawTransaction RPC method.

I would like to do this offline using code or an open-source library OR online but without the need of using an specific wallet or software.

There is neither a RPC method to create/sign the raw transaction, nor can I find any libraries to do this (offline).

Any help or guidance on how this could be achieved would be most thanked. If there is a python implementation that would be awesome.

Best Answer

ethereumjs-tx is a library with this example:

npm install ethereumjs-tx

const Tx = require('ethereumjs-tx').Transaction
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex')

var rawTx = {
  nonce: '0x00',
  gasPrice: '0x09184e72a000', 
  gasLimit: '0x2710',
  to: '0x0000000000000000000000000000000000000000', 
  value: '0x00', 
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}

var tx = new Tx(rawTx)
tx.sign(privateKey)

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