Ethereum Transaction From Scratch In Rust
To use this crate first create Transaction struct
use H160;
let tx = Transaction ;
You can also specify data if you want to call or deploy a smart contract:
use H160;
let data = vec!;
let tx = Transaction
After creating the struct you can just call the sign
method with your private key:
use H256;
// Add your private key
// This is a know private key from hardhat test accounts
let private_key =
H256 from_str.unwrap;
// Sign the transaction
let tx_bytes = tx.sign;
If you want to send your signed transaction you will need to crate a json object from the signed bytes:
use Bytes;
// Convert Vec<u8> to Bytes so it can be serialized
let tx_bytes = from;
// Convert it to JSON value
let signed_tx = to_value.unwrap;
You can find detailed example in examples
Acknowledgments
Credit goes to synlestidae creator of ethereum-tx-sign. His crate helped me to understand how are ethereum transactions encoded and signed.
This crate is just simpler implementation of ethereum-tx-sign.
Disclaimer
This is untested, unaudited software don't use in production or with real crypto!!!