# How do I create a StorageMap of Vectors with a tuple of 2 strings?

**URL:** <https://forum.fuel.network/t/how-do-i-create-a-storagemap-of-vectors-with-a-tuple-of-2-strings/5081>\
**Category:** Sway\
**Created:** [April 11, 2024, 2:51pm UTC](https://forum.fuel.network/t/how-do-i-create-a-storagemap-of-vectors-with-a-tuple-of-2-strings/5081 "2024-04-11T14:51:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luisburigo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/luisburigo/32/4160_2.png) [@luisburigo](https://forum.fuel.network/u/luisburigo)\
**Post date:** [April 11, 2024, 2:51pm UTC](https://forum.fuel.network/t/how-do-i-create-a-storagemap-of-vectors-with-a-tuple-of-2-strings/5081/1 "2024-04-11T14:51:04Z")

</div>

I need to store this structure in storage:

```auto
// sha256(String)
'0x98798....': [
    // Vec<(String, String)>
    ['String Value', 'String Value']
]

```

I tried implementing it in the following ways:

1. 
  - `StorageMap<b256, StorageBytes>`  
In this case, the StorageBytes represents my `Vec<(String, String)>` . I tried to allocate and calculate the bytes for each item, but without success.

2. 
  - `StorageMap<b256, StorageVec<(StorageString, StorageString)>>`  
In this case, I couldn’t find a way to insert a `StorageString` into the `StorageVec` (I think it might not be possible).

3. 
  - `StorageMap<b256, StorageVec<Metadata>`  
Using a Struct with a String is not possible because the type “pointer” is not allowed in storage.

```sway
struct Metadata {
  name: String,
  value: String,
}

```

* * *

To better illustrate, I need to implement the same structure below in Solidity for Sway:

```auto
struct Metadata {
    string name;
    string value;
}
    
mapping(address => Metadata[]) public metadataMap;

```

What the best way to implement this structure?

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/nick/32/2330_2.png) [@nick](https://forum.fuel.network/u/nick)\
**Post date:** [April 16, 2024, 1:37pm UTC](https://forum.fuel.network/t/how-do-i-create-a-storagemap-of-vectors-with-a-tuple-of-2-strings/5081/2 "2024-04-16T13:37:30Z")

</div>

Pinging DevRel, will respond shortly.

---

<div class="post-metadata">

**Author:** ![calldelegation](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/calldelegation/32/1484_2.png) [@calldelegation](https://forum.fuel.network/u/calldelegation)\
**Post date:** [April 17, 2024, 2:40am UTC](https://forum.fuel.network/t/how-do-i-create-a-storagemap-of-vectors-with-a-tuple-of-2-strings/5081/3 "2024-04-17T02:40:23Z")

</div>

Hey @luisburigo! Apologies for the late reply but a StorageVec of String inside StorageMap of a b256 is possible.

You got it bang on with #2

Here is a working example for you:

```auto
contract;

use std::{
    auth::msg_sender,
    hash::Hash,
    storage::{
        storage_bytes::*,
        storage_string::*,
        storage_vec::*,
    },
    string::String,
};

storage {
    metadata: StorageMap<b256, StorageVec<StorageString>> = StorageMap {},
}

abi MyContract {
    #[storage(read, write)]
    fn test_function() -> bool;
}

impl MyContract for Contract {
    #[storage(read, write)]
    fn test_function() -> bool {
        // Setup and initalize vec storage
        let some_b256 = 0x0000000000000000000000000000000000000000000000000000000000000000;
        storage.metadata.insert(some_b256, StorageVec{});

        // Setup and initialize string storage
        storage.metadata.get(some_b256).push(StorageString{});

        // Store string
        let my_string = String::from_ascii_str("Fuel is blazingly fast");
        storage.metadata.get(some_b256).get(0).unwrap().write_slice(my_string);
        
        assert(storage.metadata.get(some_b256).get(0).unwrap().read_slice().unwrap() == my_string);
        true
    }
}

#[test]
fn test_example() {
    let contract_abi = abi(MyContract, CONTRACT_ID);
    let _ = contract_abi.test_function();
}

```

Hope this helps! 😄

---

<div class="post-metadata">

**Author:** ![luisburigo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/luisburigo/32/4160_2.png) [@luisburigo](https://forum.fuel.network/u/luisburigo)\
**Post date:** [April 19, 2024, 4:27pm UTC](https://forum.fuel.network/t/how-do-i-create-a-storagemap-of-vectors-with-a-tuple-of-2-strings/5081/4 "2024-04-19T16:27:48Z")

</div>

Hello! Thank you for the response.

I implemented it, and the tests in Sway worked just fine, however, when running it through the TS SDK, the vector decode did not work.

I made another implementation to solve my case, which is at this link: [sway-snippets/features/metadata-storage at main · luisburigo/sway-snippets · GitHub](https://github.com/luisburigo/sway-snippets/tree/main/features/metadata-storage)

Thank you for the help! ❤

---

<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:** [May 10, 2024, 12:28pm UTC](https://forum.fuel.network/t/how-do-i-create-a-storagemap-of-vectors-with-a-tuple-of-2-strings/5081/5 "2024-05-10T12:28:29Z")

</div>

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