Let's say I have the following transaction information:


Along with anything else you may need about the network broadly (such as chain_id).

Is it possible to construct an analogous raw transaction from this information without knowing the private key of the sender?

Feel free to use your favorite Web3 SDK.


A raw transaction is just all the transaction parameters encoded in the RLP format. A raw transaction consists of (in this order):

  • Nonce;
  • Gas price;
  • Gas limit;
  • To address;
  • Value;
  • Data.

You don't need the private key of the sender: to get the raw transaction, you can simply encode it using RLP(Nonce, Gas Price, Gas limit, To, Value, Data). Here's an example implementation in JavaScript (using ethereumjs/rlp):

import { encode } from 'rlp';

const transaction = {
  nonce: '0x1e7',
  gasPrice: '0x2e90edd000',
  gasLimit: '0x30d40',
  to: '0xbd064928cdd4fd67fb99917c880e6560978d7ca1',
  value: '0xde0b6b3a7640000',
  data: '0x'

// Raw transaction as Buffer
const rawTransaction = encode([transaction.nonce, transaction.gasPrice, transaction.gasLimit, transaction.to, transaction.value, transaction.data]);

This results in the following raw transaction:


The only part where a private key is required, is to sign the transaction. A signed transaction is basically the raw transaction with the v, r and s signature (of the raw transaction) added to it: RLP(Nonce, Gas Price, Gas limit, To, Value, Data, v, r, s). The chain ID is encoded in the v parameter (see EIP-155).

Here's an example of how to sign the transaction and get the signed transaction:

import { randomBytes } from 'crypto';
import { ecsign, keccak256 } from 'ethereumjs-util';
import { encode } from 'rlp';

// Randomly generated 32 byte private key
const privateKey = randomBytes(32);

const transaction = {
  nonce: '0x1e7',
  gasPrice: '0x2e90edd000',
  gasLimit: '0x30d40',
  to: '0xbd064928cdd4fd67fb99917c880e6560978d7ca1',
  value: '0xde0b6b3a7640000',
  data: '0x',
  chainId: 1

const params = [transaction.nonce, transaction.gasPrice, transaction.gasLimit, transaction.to, transaction.value, transaction.data];

// Raw transaction as Buffer
const rawTransaction = encode(params);
const hash = keccak256(rawTransaction);

// Signature of the hash of the raw transaction
const { v, r, s } = ecsign(hash, privateKey, transaction.chainId);

// RLP encoded signed transaction as Buffer
const signedTransaction = encode([...params, v, r, s]);

Note the extra chainId property of transaction, this is required to get the correct value for v. If we assume our signature is the one mentioned in the example transaction, the signed transaction looks like this:


This is the full transaction that can be broadcast to the network. You can verify this through MyCrypto's broadcast tool for example.

  • Nice! I think your code creates an unsigned transaction which cannot be directly sent to a network to replay the transaction. Can you include the signing step with v, r, s also please. – Peteris Sep 8 '20 at 20:01
  • Correct, the raw transaction cannot be broadcast, since you need a valid signature to send a transaction. I updated the answer to include the signing. – Morten Sep 8 '20 at 20:17

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.