diff --git a/ethers-core/src/types/block.rs b/ethers-core/src/types/block.rs index 75beac62..c516318c 100644 --- a/ethers-core/src/types/block.rs +++ b/ethers-core/src/types/block.rs @@ -9,7 +9,7 @@ use serde::{ ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer, }; -use std::{fmt::Formatter, str::FromStr}; +use std::{fmt, fmt::Formatter, str::FromStr}; use thiserror::Error; /// The block type returned from RPC calls. @@ -579,6 +579,17 @@ impl FromStr for BlockNumber { } } +impl fmt::Display for BlockNumber { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + BlockNumber::Number(ref x) => format!("0x{:x}", x).fmt(f), + BlockNumber::Latest => f.write_str("latest"), + BlockNumber::Earliest => f.write_str("earliest"), + BlockNumber::Pending => f.write_str("pending"), + } + } +} + #[cfg(test)] #[cfg(not(feature = "celo"))] mod tests {