Skip to content

Commit e093f62

Browse files
committed
Add example for instantiate2_address_evm_compatible
1 parent bd8af7d commit e093f62

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/std/src/addresses.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,27 @@ pub fn instantiate2_address(
328328
/// However, some chains use 20 for compatibility with the Ethereum ecosystem.
329329
/// Using any other value than 32 requires a coordination with the chain implementation.
330330
/// See also <https://github.com/CosmWasm/cosmwasm/issues/2155>.
331+
///
332+
/// ## Examples
333+
///
334+
/// ```
335+
/// use cosmwasm_std::{instantiate2_address_impl, CanonicalAddr, HexBinary, Instantiate2AddressError};
336+
///
337+
/// fn instantiate2_address_evm_compatible(
338+
/// checksum: &[u8],
339+
/// creator: &CanonicalAddr,
340+
/// salt: &[u8],
341+
/// ) -> Result<CanonicalAddr, Instantiate2AddressError> {
342+
/// instantiate2_address_impl(checksum, creator, salt, b"", 20)
343+
/// }
344+
///
345+
/// let checksum = HexBinary::from_hex("13a1fc994cc6d1c81b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5").unwrap();
346+
/// let creator = CanonicalAddr::from(HexBinary::from_hex("9999999999aaaaaaaaaabbbbbbbbbbcccccccccc").unwrap());
347+
/// let salt = b"\x61";
348+
///
349+
/// let address = instantiate2_address_evm_compatible(&checksum, &creator, salt).unwrap();
350+
/// assert_eq!(address, HexBinary::from_hex("5e865d3e45ad3e961f77fd77d46543417ced44d9").unwrap());
351+
/// ```
331352
#[doc(hidden)]
332353
#[inline] // Only call this through a wrapper like instantiate2_address or a custom instantiate2_address_evm_compatible
333354
pub fn instantiate2_address_impl(

0 commit comments

Comments
 (0)