-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(transactions): encode eip1559 #45
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f2b813
feat(transactions): encode eip1559
yash-atreya 50f5cc5
Merge branch 'main' into encode_decode_txs
yash-atreya 089b1c0
Merge branch 'main' into encode_decode_txs
yash-atreya 4b20ae2
recover signer
yash-atreya d12ce03
nit
yash-atreya 144f6bc
Merge branch 'main' into zerosnacks/encode-decode-alloy-issue-283
zerosnacks af8cd0a
improve docs
zerosnacks cfaeb3a
rename sign_transaction
zerosnacks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! Encode and decode transactions | ||
use alloy::{ | ||
consensus::{SignableTransaction, TxEip1559}, | ||
eips::eip2930::AccessList, | ||
primitives::{address, b256, hex, Signature, TxKind, U256}, | ||
}; | ||
use eyre::Result; | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// EIP1559 transaction: <https://etherscan.io/tx/0x0ec0b6a2df4d87424e5f6ad2a654e27aaeb7dac20ae9e8385cc09087ad532ee0> | ||
let hash = b256!("0ec0b6a2df4d87424e5f6ad2a654e27aaeb7dac20ae9e8385cc09087ad532ee0"); | ||
|
||
// Signer of the transaction. | ||
let signer = address!("DD6B8b3dC6B7AD97db52F08a275FF4483e024CEa"); | ||
|
||
let tx = TxEip1559 { | ||
chain_id: 1, | ||
nonce: 0x42, | ||
gas_limit: 44386, | ||
to: TxKind::Call( address!("6069a6c32cf691f5982febae4faf8a6f3ab2f0f6")), | ||
value: U256::from(0_u64), | ||
input: hex!("a22cb4650000000000000000000000005eee75727d804a2b13038928d36f8b188945a57a0000000000000000000000000000000000000000000000000000000000000000").into(), | ||
max_fee_per_gas: 0x4a817c800, | ||
max_priority_fee_per_gas: 0x3b9aca00, | ||
access_list: AccessList::default(), | ||
}; | ||
|
||
let sig = Signature::from_scalars_and_parity( | ||
b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), | ||
b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), | ||
false, | ||
) | ||
.unwrap(); | ||
|
||
let signed_tx = tx.into_signed(sig); | ||
|
||
// Match hash | ||
assert_eq!(*signed_tx.hash(), hash); | ||
|
||
let recovered_signer = signed_tx.recover_signer().unwrap(); | ||
assert_eq!(recovered_signer, signer); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the goal of the example? To recover the signer from the transaction? Some additional comments would be great
For #44, is it within the scope of this PR to also show the other transaction types (are they different?)? If so, should we add specific files for each (like we do for
send_*_transaction
)