# Passing Variant as Argument to a function using Motoko

**URL:** <https://forum.dfinity.org/t/passing-variant-as-argument-to-a-function-using-motoko/15189>\
**Category:** Language Support\
**Created:** [August 30, 2022, 2:29pm UTC](https://forum.dfinity.org/t/passing-variant-as-argument-to-a-function-using-motoko/15189 "2022-08-30T14:29:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karim](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/karim/32/4680_2.png) [@karim](https://forum.dfinity.org/u/karim)\
**Post date:** [August 30, 2022, 2:29pm UTC](https://forum.dfinity.org/t/passing-variant-as-argument-to-a-function-using-motoko/15189/1 "2022-08-30T14:29:50Z")

</div>

I’ve seen solutions for calling functions that require a variant as an argument using JS but wasn’t able to solve this using Motoko. Let’s say I have a canister called `RemoteCanister` that exposes a function `testVariant` which requires an argument of a custom type `Request` as defined here:

```auto
  // Types
  type MyType = {
    #one : Text;
    #two : Nat;
  };

  type Request = {
    choose : MyType;
    headline: Text;
  };

  // Function
  public shared(msg) func testVariant(data : Request) : async Text {
    return "success!";
  };

```

I want to call this function from another canister. How would I pass the argument for type `MyType` when this is a variant? This is the function call in the second canister:

```auto
  public shared(msg) func callTestVariant() : async Text {
    let response : Text = await RemoteActor.testVariant(#two: 12, "my string");
    return "yeahcool!";
  };

```

I’ve also tried other ways like `({two: 12}, "my string"})` or simply `(12, "my string")` hoping it would infer the type automatically. How does one do this?

---

<div class="post-metadata">

**Author:** ![rossberg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rossberg/32/795_2.png) [@rossberg](https://forum.dfinity.org/u/rossberg)\
**Post date:** [August 30, 2022, 3:16pm UTC](https://forum.dfinity.org/t/passing-variant-as-argument-to-a-function-using-motoko/15189/2 "2022-08-30T15:16:55Z")

</div>

> [@karim](#):
>
> `RemoteActor.testVariant(#two: 12, "my string");`

The invocation would be

```auto
RemoteActor.testVariant(#two(12), "my string");

```

---

<div class="post-metadata">

**Author:** ![karim](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/karim/32/4680_2.png) [@karim](https://forum.dfinity.org/u/karim)\
**Post date:** [August 30, 2022, 6:02pm UTC](https://forum.dfinity.org/t/passing-variant-as-argument-to-a-function-using-motoko/15189/3 "2022-08-30T18:02:50Z")

</div>

Beautiful! Thank you!

Actually, it’s `await RemoteActor.testVariant({choose = #two(12); headline = "my string"});` in this specific case because of the subtypes, I guess.
