# Is it possible to store Struct in Storage

**URL:** <https://forum.fuel.network/t/is-it-possible-to-store-struct-in-storage/6390>\
**Category:** Sway\
**Created:** [August 1, 2024, 9:06am UTC](https://forum.fuel.network/t/is-it-possible-to-store-struct-in-storage/6390 "2024-08-01T09:06:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahesh\_d\_luffy](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@mahesh\_d\_luffy](https://forum.fuel.network/u/mahesh_d_luffy)\
**Post date:** [August 1, 2024, 9:06am UTC](https://forum.fuel.network/t/is-it-possible-to-store-struct-in-storage/6390/1 "2024-08-01T09:06:24Z")

</div>

Hi @danielbate@naz3eh , I am currently facing an issue with struct storage

Contract :

```auto
contract;
 
pub struct Point {
    question_id :u64,
    yesnftCount: u64,
    nonftCount: u64,
    question: str,
    starttime : u64,
    endtime : u64
}

storage {
    counter: u64 = 0,
    question_info: StorageMap<(u64,Point)> = StorageMap{},
}
  
abi MyContract {
    #[storage(read, write)]
    fn add_question(question_id: b256, question_info: Point);

     #[storage(read)]
    fn get_question(question_id: str) -> Option<Point>;
    
}
 
impl MyContract for Contract {

    #[storage(read, write)]
    fn add_question(question_id : b256 , question_info : Point){
        let incremented : u64 = storage.counter.read() + 1;
        storage.counter.write(incremented);
        // storage.question_info.write(question_id, _question_info);
    }

    #[storage(read)]
    fn get_question(question_id: str) -> Option<Point> {
        storage.question_info.get(question_id)
    }
}
 

```

Blocker That I’m Facing

 ![Screenshot 2024-08-01 at 14.34.34](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/1/1cb6fc0388f16fb9fd8656e5dd6ae331a3c1eac2.png)

I am trying to store Struct details in the struct , how can i store it ?

Fuelup show :

 ![Screenshot 2024-07-17 at 14.31.08](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/c/c25e67bb2206bbb18eca24fa1b1d1e0cd40309f5.jpeg)

---

<div class="post-metadata">

**Author:** ![p.s](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/p.s/32/2491_2.png) [@p.s](https://forum.fuel.network/u/p.s)\
**Post date:** [August 1, 2024, 9:30am UTC](https://forum.fuel.network/t/is-it-possible-to-store-struct-in-storage/6390/2 "2024-08-01T09:30:38Z")

</div>

Hey @mahesh_d_luffy 👋

You can indeed store a Struct in a storage map.

Your declaration of the StorageMap looks a little off though, as it requires a key/value pair like `StorageMap<Key, Value>` (see the [docs](https://docs.fuel.network/docs/sway/common-collections/storage_map/#creating-a-new-storage-map) for more information).

The following builds successfully for me on `v0.62.0` of forc.

```sway
contract;

use std::hash::Hash;

pub struct Point {
    question_id :u64,
    yesnftCount: u64,
    nonftCount: u64,
    // question: str,
    starttime : u64,
    endtime : u64
}

storage {
    counter: u64 = 0,
    question_info: StorageMap<b256, Point> = StorageMap::<b256, Point>{},
}

abi MyContract {
    #[storage(read, write)]
    fn add_question(question_id: b256, question_info: Point);

     #[storage(read)]
    fn get_question(question_id: b256) -> Point;

}

impl MyContract for Contract {

    #[storage(read, write)]
    fn add_question(question_id: b256, question_info : Point){
        let incremented : u64 = storage.counter.read() + 1;
        storage.counter.write(incremented);
        storage.question_info.insert(question_id, question_info);
    }

    #[storage(read)]
    fn get_question(question_id: b256) -> Point {
        storage.question_info.get(question_id).read()
    }
}

```

---

<div class="post-metadata">

**Author:** ![mahesh\_d\_luffy](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@mahesh\_d\_luffy](https://forum.fuel.network/u/mahesh_d_luffy)\
**Post date:** [August 1, 2024, 9:47am UTC](https://forum.fuel.network/t/is-it-possible-to-store-struct-in-storage/6390/3 "2024-08-01T09:47:21Z")

</div>

Hi @p.s , I understood , how can we add String type in the struct , I want to store question on it ,

is there any other alternate way to store a question (string) type in it.

Thanks in advance 🙂 .

---

<div class="post-metadata">

**Author:** ![p.s](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/p.s/32/2491_2.png) [@p.s](https://forum.fuel.network/u/p.s)\
**Post date:** [August 1, 2024, 10:11am UTC](https://forum.fuel.network/t/is-it-possible-to-store-struct-in-storage/6390/4 "2024-08-01T10:11:05Z")

</div>

Hey 👋

I _believe_ you could use a `StorageString` for this - read more in our [docs](https://docs.fuel.network/docs/sway/blockchain-development/storage/#storagestring).

Hope this helps 🙂
