# Converting "fuel..." addresses to Bits256?

**URL:** <https://forum.fuel.network/t/converting-fuel-addresses-to-bits256/4291>\
**Category:** Rust SDK\
**Tags:** testnet\
**Created:** [February 15, 2024, 5:24am UTC](https://forum.fuel.network/t/converting-fuel-addresses-to-bits256/4291 "2024-02-15T05:24:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [February 15, 2024, 5:24am UTC](https://forum.fuel.network/t/converting-fuel-addresses-to-bits256/4291/1 "2024-02-15T05:24:53Z")

</div>

Both `AssetId` and `ContractId` are roughly typed like so in Sway:

```rust
struct AssetId {
    value: b256
}

```

In the Rust SDK, to convert a hex-like string (either a ContractId or AssetId) to Bits256 is straightforward:

```rust
let contr: ContractId = instance.contract_id().into();
let bits: Bits256 = Bits256::from_hex_str(contr.to_string().as_str()).unwrap();
println!("Bits: {:?}", bits); 

```

and this works fine, but how about if you have a `Bech32`-like address where the “string” is actually something like `fuel15ckkwj6uepv5u2nxpl5sft56unp82s0cean8m6s476dmeu5pdejssxt753`?

as an example:

```rust
let bech = Bech32ContractId { 
    hrp: "fuel", 
    hash: "a62d674b5cc8594e2a660fe904ae9ae4c27541f8cf667dea15f69bbcf2816e65"
};

let str_out = bech.to_string(); // fuel15ckkwj6uepv5u2nxpl5sft56unp82s0cean8m6s476dmeu5pdejssxt753

// Converting from contr to Bits256 is via ContractId like so:
let contr: ContractId = bech.into();
let bits = Bits256::from_hex_str(contr.to_string().as_str()).unwrap();

// But how to go from a raw string (fuel15ckkwj6uepv5u2nxpl5sft56unp82s0cean8m6s476dmeu5pdejssxt753)
// to Bits256?

```

---

<div class="post-metadata">

**Author:** ![diyahir](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/diyahir/32/1075_2.png) [@diyahir](https://forum.fuel.network/u/diyahir)\
**Post date:** [February 15, 2024, 9:59am UTC](https://forum.fuel.network/t/converting-fuel-addresses-to-bits256/4291/2 "2024-02-15T09:59:45Z")

</div>

I agree, can we just abandon the bech32 address?

There is little to 0 benefit from having it, and it’s just causing type-casting pains

This is a common ‘Cosmos ecosystem trap’ where having a bech32 address looks cool because you have some relationship between chain ↔ user with the address but in reality there are hundreds of chains and it’s just a pain to manage one wallet (seed phrase) with many different bech32 addresses

---

<div class="post-metadata">

**Author:** ![hal3e](https://avatars.discourse-cdn.com/v4/letter/h/958977/32.png) [@hal3e](https://forum.fuel.network/u/hal3e)\
**Post date:** [February 15, 2024, 10:45am UTC](https://forum.fuel.network/t/converting-fuel-addresses-to-bits256/4291/3 "2024-02-15T10:45:46Z")

</div>

You can convert `ContractId` directly into `[u8, 32]` :

```auto
    let contract_id = ContractId::default();
    let _b256 = Bits256(contract_id.into());

```

for `Bech32ContractId` you can convert it first to `ContractId` and then to `[u8, 32]`

```auto
    let bech_contract_id = Bech32ContractId::default();
    let contract_id2: ContractId = bech_contract_id.into();
    let _b256 = Bits256(contract_id2.into());

```

---

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [February 17, 2024, 6:27am UTC](https://forum.fuel.network/t/converting-fuel-addresses-to-bits256/4291/4 "2024-02-17T06:27:58Z")

</div>

got it! Thanks so much

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [March 9, 2024, 2:28am UTC](https://forum.fuel.network/t/converting-fuel-addresses-to-bits256/4291/5 "2024-03-09T02:28:23Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
