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]);
console.log(rawTransaction.toString('hex'));
This results in the following raw transaction:
ec8201e7852e90edd00083030d4094bd064928cdd4fd67fb99917c880e6560978d7ca1880de0b6b3a764000080
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).