-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: added cookbook entry to compute raw transaction (#1857).
- Loading branch information
Showing
3 changed files
with
28 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ snippets of code that are in general useful. | |
_toc: | ||
|
||
react-native | ||
transactions | ||
|
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,24 @@ | ||
_section: Transactions @<cookbook--transactions> | ||
|
||
_subsection: Compute the raw transaction @<cookbook--compute-raw-transaction> | ||
|
||
_code: @lang<javascript> | ||
|
||
function getRawTransaction(tx) { | ||
function addKey(accum, key) { | ||
if (tx[key]) { accum[key] = tx[key]; } | ||
return accum; | ||
} | ||
|
||
// Extract the relevant parts of the transaction and signature | ||
const txFields = "accessList chainId data gasPrice gasLimit maxFeePerGer maxPriorityFeePerGas nonce to type value".split(" "); | ||
const sigFields = "v r s".split(" "); | ||
|
||
// Seriailze the signed transaction | ||
const raw = utils.serializeTransaction(txFields.reduce(addKey, { }), sigFields.reduce(addKey, { })); | ||
|
||
// Double check things went well | ||
if (utils.keccak256(raw) !== tx.hash) { throw new Error("serializing failed!"); } | ||
|
||
return raw; | ||
} |