Skip to content
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

[Feature][Primitive] Allow ParseUnits to be converted to u128 #598

Closed
NicolasWent opened this issue Apr 9, 2024 · 1 comment · Fixed by #646
Closed

[Feature][Primitive] Allow ParseUnits to be converted to u128 #598

NicolasWent opened this issue Apr 9, 2024 · 1 comment · Fixed by #646
Labels
enhancement New feature or request

Comments

@NicolasWent
Copy link

NicolasWent commented Apr 9, 2024

Component

primitives

Describe the feature you would like

The gas configurations have been set to u128 instead of U256 in the alloy TransactionBuilder

It would be nice to have an into() implementation for a ParseUnits to convert it directly to u128.

This way we would be able to set the max priority fee per gas (and max_fee_per_gas) more smoothly:

// Currently not working:
my_transaction_builder.max_priority_fee_per_gas(parse_units("0.1", "gwei").unwrap().into());

Instead of the current workaround:

let max_priority_fee_per_gas: U256 = parse_units("0.1", "gwei").unwrap().into();
my_transaction_build.max_priority_fee_per_gas(max_priority_fee_per_gas.to());
@NicolasWent NicolasWent added the enhancement New feature or request label Apr 9, 2024
@DaniPopes
Copy link
Member

DaniPopes commented Apr 9, 2024

This should be TryFrom since 256 -> 128 bits is fallible.
Other options:

  • parse_units(...)?.get_absolute().to()
  • 0.1e9 as u128
  • const GWEI: u128 = 1e9 as u128; GWEI / 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants