You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Fallback to legacy transaction for non-eip1559 chains should give a bit of additional chain support.
Turns out this one particular network still doesn't support Legacy
Received promise rejected instead of resolved
Rejected to value: [InvalidInputRpcError: Missing or invalid parameters.
Double check you have provided the correct parameters.·
URL: https://rpc.startale.com/astar-zkevm
Request body: {"method":"eth_sendRawTransaction","params":["0xe480838a3ea082520894759e10411dda5138e331b7ad5ce1b937550db7378080820ec08080"]}·
Details: invalid sender
Version: 2.21.1]
Unfortunately, it will not suffice to simply replace gas fee data. We may also have to change the signature (to incorporate EIP-155.
PR Type
enhancement, tests
Description
Added getGasData function to handle gas fee estimation for both EIP-1559 and legacy transactions.
Modified populateTx function to use getGasData for gas fee values.
Introduced error handling for non-EIP-1559 chains.
Added unit test for populating non-EIP-1559 transactions.
Changes walkthrough 📝
Relevant files
Enhancement
transaction.ts
Add legacy fallback support for non-EIP-1559 chains
src/utils/transaction.ts
Added getGasData function to handle gas fee estimation for both EIP-1559 and legacy transactions.
Modified populateTx function to use getGasData for gas fee values.
Introduced error handling for non-EIP-1559 chains.
-return { gasPrice: await provider.getGasPrice() };+try {+ return { gasPrice: await provider.getGasPrice() };+} catch (error) {+ logger.error('Failed to get gas price:', error);+ throw error;+}
Suggestion importance[1-10]: 9
Why: Adding error handling for provider.getGasPrice() prevents unhandled promise rejections, which is crucial for maintaining application stability and reliability.
9
Add a fallback for chainId in populateTx to handle missing values
Ensure that the populateTx function handles the scenario where chainId is not provided in the transaction object, to avoid potential runtime errors.
Why: Ensuring that populateTx handles scenarios where chainId is not provided prevents potential runtime errors, improving the robustness of the function.
8
Maintainability
Refactor getGasData to improve modularity by separating fee fetching logic
Refactor the getGasData function to separate concerns between fetching EIP-1559 and legacy gas data into distinct functions for better modularity and readability.
export async function getGasData(
provider: PublicClient
): Promise<FeeValuesEIP1559 | FeeValuesLegacy> {
try {
- return await provider.estimateFeesPerGas();+ return await fetchEIP1559Fees(provider);
} catch (error: unknown) {
if (error instanceof Eip1559FeesNotSupportedError) {
- console.warn(`${error.shortMessage} Using Legacy Gas Fees`);+ logger.warn(`${error.shortMessage} Using Legacy Gas Fees`);+ return fetchLegacyFees(provider);
}
- return { gasPrice: await provider.getGasPrice() };+ throw error;
}
}
+async function fetchEIP1559Fees(provider: PublicClient): Promise<FeeValuesEIP1559> {+ return await provider.estimateFeesPerGas();+}+async function fetchLegacyFees(provider: PublicClient): Promise<FeeValuesLegacy> {+ return { gasPrice: await provider.getGasPrice() };+}
Suggestion importance[1-10]: 8
Why: Refactoring the getGasData function to separate concerns enhances code readability and maintainability, making it easier to manage and test individual parts of the code.
8
Best practice
Replace console logging with a more robust logging framework
Replace the use of console.warn with a more robust logging mechanism that allows for better control over logging levels and formats, especially for production environments.
-console.warn(`${error.shortMessage} Using Legacy Gas Fees`);+logger.warn(`${error.shortMessage} Using Legacy Gas Fees`);
Suggestion importance[1-10]: 7
Why: Using a robust logging framework instead of console.warn is a best practice for better control over logging levels and formats, especially in production environments. However, it is not a critical issue.
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.
User description
Fallback to legacy transaction for non-eip1559 chains should give a bit of additional chain support.
Turns out this one particular network still doesn't support Legacy
Unfortunately, it will not suffice to simply replace gas fee data. We may also have to change the signature (to incorporate EIP-155.
PR Type
enhancement, tests
Description
getGasData
function to handle gas fee estimation for both EIP-1559 and legacy transactions.populateTx
function to usegetGasData
for gas fee values.Changes walkthrough 📝
transaction.ts
Add legacy fallback support for non-EIP-1559 chains
src/utils/transaction.ts
getGasData
function to handle gas fee estimation for bothEIP-1559 and legacy transactions.
populateTx
function to usegetGasData
for gas fee values.utils.transaction.test.ts
Add unit test for legacy transaction support
tests/unit/utils.transaction.test.ts
serializeTransaction
import for testing purposes.