# Error \`No method named "push" found for type "StorageVec\<u64\>".\` during usage of nested StorageVec inside a StorageMap

**URL:** <https://forum.fuel.network/t/error-no-method-named-push-found-for-type-storagevec-u64-during-usage-of-nested-storagevec-inside-a-storagemap/3132>\
**Category:** Sway\
**Created:** [October 4, 2023, 2:29pm UTC](https://forum.fuel.network/t/error-no-method-named-push-found-for-type-storagevec-u64-during-usage-of-nested-storagevec-inside-a-storagemap/3132 "2023-10-04T14:29:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fuel/32/1677_2.png) [@fuel](https://forum.fuel.network/u/fuel)\
**Post date:** [October 4, 2023, 2:29pm UTC](https://forum.fuel.network/t/error-no-method-named-push-found-for-type-storagevec-u64-during-usage-of-nested-storagevec-inside-a-storagemap/3132/1 "2023-10-04T14:29:06Z")

</div>

# Error `No method named "push" found for type "StorageVec<u64>".` during usage of nested StorageVec inside a StorageMap

Hello friends ✨  
We are in the process of building our perps and have been faced with a strange problem: I’m trying to store a storage list of opened orders for each user (to make `cancel_all` func)

We are having the next storage item ` orders_by_owner: StorageMap<Address, StorageVec<u64>> = StorageMap {},` but during the build, I got the next error in editing of the orders list place

```rs
let mut orders_by_owner = storage.orders_by_owner.get(owner).read();
orders_by_owner.push(id);
//^^^^ No method named "push" found for type "StorageVec<u64>".
storage.orders_by_owner.insert(owner, orders_by_owner);

```

Here I created a simple contract to show that error in the simplest way:

> **[GitHub - chlenc/nested-storage-vec-example](https://github.com/chlenc/nested-storage-vec-example)**
>
> Contribute to chlenc/nested-storage-vec-example development by creating an account on GitHub.

```rs
contract;
use std::hash::*;
use std::storage::storage_vec::*;

storage{
    v: StorageMap<Address, StorageVec<u64>> = StorageMap {},
}

abi MyContract {
    #[storage(read, write)]
    fn test_function(n: u64);
}

impl MyContract for Contract {
    #[storage(read, write)]
    fn test_function(n: u64) {
        let address = msg_sender_address();

        let mut v = storage.v.get(address).read();
        v.push(n); //error No method named "push" found for type "StorageVec<u64>".
        storage.v.insert(address, v);
    }
}

pub fn msg_sender_address() -> Address {
    match std::auth::msg_sender().unwrap() {
        Identity::Address(identity) => identity,
        _ => revert(0),
    }
}

```

## How to reproduce?

```auto
git clone https://github.com/chlenc/nested-storage-vec-example.git
cd nested-storage-vec-example
forc build

```

## toolchain

```auto
Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup

installed toolchains
--------------------
beta-3-aarch64-apple-darwin
beta-4-rc.2-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
beta-4-aarch64-apple-darwin
hotfix
my-custom-toolchain

active toolchain
-----------------
latest-aarch64-apple-darwin (default)
  forc : 0.46.0
    - forc-client
      - forc-deploy : 0.46.0
      - forc-run : 0.46.0
    - forc-doc : 0.46.0
    - forc-explore : 0.28.1
    - forc-fmt : 0.46.0
    - forc-index : 0.21.0
    - forc-lsp : 0.46.0
    - forc-tx : 0.46.0
    - forc-wallet : 0.3.0
  fuel-core : 0.20.5
  fuel-core-keygen : Error getting version string
  fuel-indexer : 0.21.0

fuels versions
---------------
forc : 0.45
forc-wallet : 0.45

```

---

<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:** [October 4, 2023, 3:55pm UTC](https://forum.fuel.network/t/error-no-method-named-push-found-for-type-storagevec-u64-during-usage-of-nested-storagevec-inside-a-storagemap/3132/2 "2023-10-04T15:55:03Z")

</div>

Hey @fuel thanks for using the forum! Your problem is on this line:

`let mut v = storage.v.get(address).read();`

1. Your `.get()` returns type `StorageKey`
2. So when you do a `.read()`after it is loading in an **empty struct** because you’ve defined it as `StorageMap {}` previously
3. Since the `StorageMap` keeps the storage in place there is no need to insert again either

the updated example would look like this

```auto
impl MyContract for Contract {
    #[storage(read, write)]
    fn test_function(n: u64) {
        let address = msg_sender_address();

        let mut v = storage.v.get(address);
        v.push(n);
    }
}

```

@bitzoic wrote a more comprehensive example here

```auto
contract;

use std::{storage::storage_vec::*, auth::msg_sender, hash::Hash};

storage {
    my_map: StorageMap<Identity, StorageVec<u64>> = StorageMap {},
}

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

impl MyContract for Contract {
    #[storage(read, write)]
    fn test_function() -> bool {
        // Setup and initalize storage
        let sender = msg_sender().unwrap();
        storage.my_map.insert(sender, StorageVec{});

        // Method 1
        let key_of_vec: StorageKey<StorageVec<u64>> = storage.my_map.get(sender);
        key_of_vec.push(4);

        // Method 2
        storage.my_map.get(sender).push(7);

        // Make sure that 4 is at index 0 and 7 at index 1
        assert(key_of_vec.get(0).unwrap().read() == 4);
        assert(storage.my_map.get(sender).get(1).unwrap().read() == 7);

        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:** ![fuel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fuel/32/1677_2.png) [@fuel](https://forum.fuel.network/u/fuel)\
**Post date:** [October 4, 2023, 5:40pm UTC](https://forum.fuel.network/t/error-no-method-named-push-found-for-type-storagevec-u64-during-usage-of-nested-storagevec-inside-a-storagemap/3132/3 "2023-10-04T17:40:47Z")

</div>

Oh, Nice!!!  
I can do that even better using

```auto
  // Method 2
        storage.my_map.get(sender).push(7);

```

@calldelegation @bitzoic Thank you guys ❤

---

<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:** [October 25, 2023, 1:41pm UTC](https://forum.fuel.network/t/error-no-method-named-push-found-for-type-storagevec-u64-during-usage-of-nested-storagevec-inside-a-storagemap/3132/4 "2023-10-25T13:41:09Z")

</div>

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