# Dynamically create an object from Actor class within cli

**URL:** <https://forum.dfinity.org/t/dynamically-create-an-object-from-actor-class-within-cli/4274>\
**Category:** Developers\
**Created:** [May 24, 2021, 12:23pm UTC](https://forum.dfinity.org/t/dynamically-create-an-object-from-actor-class-within-cli/4274 "2021-05-24T12:23:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayazgv](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ayazgv/32/1587_2.png) [@ayazgv](https://forum.dfinity.org/u/ayazgv)\
**Post date:** [May 24, 2021, 12:23pm UTC](https://forum.dfinity.org/t/dynamically-create-an-object-from-actor-class-within-cli/4274/1 "2021-05-24T12:23:14Z")

</div>

Hello everybody!

Is there any way to create an instance of an actor class from command line?  
I mean `dfx ...`

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [May 24, 2021, 2:13pm UTC](https://forum.dfinity.org/t/dynamically-create-an-object-from-actor-class-within-cli/4274/2 "2021-05-24T14:13:29Z")

</div>

Yes. If the motoko code declares an actor class, then you can manually pass an argument to  
`dfx canister install ...` the same way you pass arguments to call (I think).

Will see if I can find an example…

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [May 24, 2021, 2:55pm UTC](https://forum.dfinity.org/t/dynamically-create-an-object-from-actor-class-within-cli/4274/3 "2021-05-24T14:55:00Z")

</div>

```auto
dfx new MyClass
cd MyClass

```

Edit file src/MyClass/main.mo to contain the actor class:

```auto
actor class (greeting : Text) {

   public func greet(name : Text) : async Text {
        return greeting # " " # name # "!";
    };

};

```

Now do:

```auto
dfx start --background
dfx canister create MyClass
dfx build MyClass
dfx canister install MyClass --argument '("Hallo")'
dfx canister call MyClass greet '("Claudio")'
dfx canister install MyClass --argument '("Ciao")' --mode reinstall
dfx canister call MyClass greet '("Claudio")'

```

Truth be told, at the moment, dfx doesn’t seem well suited to creating multiple instances of an actor class.

For that, I’d recommend using a Motoko actor that imports an actor class as a library and instantiates it programmatically, along the lines of the example here:

> **[The Internet Computer | Documentation](https://sdk.dfinity.org/docs/language-guide/actor-classes.html)**
>
> Documentation for the internet computer.

**Word of warning though:** that example should also be passing some cycles each time it instantiates an actor and currently does not. If I get a chance, I’ll turn that into another, buildable, example, adding cycle management, in the collection of examples here:

> **[dfinity/examples](https://github.com/dfinity/examples)**
>
> Example applications, microservices, and code samples for the Internet Computer
