# How to return object has shared?

**URL:** <https://forums.sui.io/t/how-to-return-object-has-shared/45686>\
**Category:** Move\
**Created:** [June 4, 2024, 6:54pm UTC](https://forums.sui.io/t/how-to-return-object-has-shared/45686 "2024-06-04T18:54:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cryptojame](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/cryptojame/32/30801_2.png) [@cryptojame](https://forums.sui.io/u/cryptojame)\
**Post date:** [June 4, 2024, 6:54pm UTC](https://forums.sui.io/t/how-to-return-object-has-shared/45686/1 "2024-06-04T18:54:11Z")

</div>

Hi all,  
Im write a init fun to create a shared object below:

```auto

fun new_pool(
    ctx: &mut TxContext
): Pool {
    let sender = ctx.sender();
    let pool = Pool {
        id: object::new(ctx),
        user: ctx.sender();
    };

    transfer::share_object(pool);
    pool
}

```

but got an error

```auto
Invalid usage of previously moved variable 'pool'.

```

plz suggest for me to fix it.  
Thanks.

---

<div class="post-metadata">

**Author:** ![alinachan](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/alinachan/32/30563_2.png) [@alinachan](https://forums.sui.io/u/alinachan)\
**Post date:** [June 10, 2024, 2:16pm UTC](https://forums.sui.io/t/how-to-return-object-has-shared/45686/3 "2024-06-10T14:16:06Z")

</div>

Actually, you cannot return an object that you previously moved, neither by value or by reference. What you could do though, is return the ID of the object you create, such as:

```auto
fun new_pool(ctx: &mut TxContext): ID {
      let pool = Pool {
          id: object::new(ctx),
          user: ctx.sender()
      };

      let pool_id = pool.get_pool_id();
      transfer::share_object(pool);
      pool_id
  }

  public fun get_pool_id(self: &Pool): ID {
    *self.id.uid_as_inner()
  }

```
