# Dynamically importing canisters with Motoko

**URL:** <https://forum.dfinity.org/t/dynamically-importing-canisters-with-motoko/10483>\
**Category:** Developers\
**Created:** [January 25, 2022, 4:45pm UTC](https://forum.dfinity.org/t/dynamically-importing-canisters-with-motoko/10483 "2022-01-25T16:45:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maithreya](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/maithreya/32/4433_2.png) [@Maithreya](https://forum.dfinity.org/u/Maithreya)\
**Post date:** [January 25, 2022, 4:45pm UTC](https://forum.dfinity.org/t/dynamically-importing-canisters-with-motoko/10483/1 "2022-01-25T16:45:46Z")

</div>

I am building a large storage network wherein I would like to have a function which takes in a text value and returns a canister.

Equivalently, I need a way to dynamically import a canister and save it as a variable.

What I have in mind is something like:

```auto
import Mystoragecanister "canister:mystoragecanister";

actor{
	func getcanister(canistername: Text) : Canister {
		return Mystoragecanister;
	};
};

```

Of course this does not work and the error I get is: “type error [M0029], unbound type Canister.”

So, how can I dynamically import Canisters with Motoko?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Maithreya](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/maithreya/32/4433_2.png) [@Maithreya](https://forum.dfinity.org/u/Maithreya)\
**Post date:** [January 25, 2022, 5:09pm UTC](https://forum.dfinity.org/t/dynamically-importing-canisters-with-motoko/10483/2 "2022-01-25T17:09:12Z")

</div>

I think I can adapt this answer [Programmatic import in Motoko - #3 by gilbert](https://forum.dfinity.org/t/programmatic-import-in-motoko/7681/3) to solve my problem. Basically, creating a type in the format if your actor and then creating a function that outputs that type should do the trick (as long as all your canisters you wish to choose from to return are of the same type).

If it works, I will post again and let you all know.

Update: This solution works like a charm!
