How to use "cowsay" project in my project?

I’m afraid this is a newbie question, but please let me know.
How can I write the code to use “cowsay canister” in my project file for “Candid UI” ?
I’ve tried everything, but it doesn’t work. If you could write a sample, it would be helpful.Thank you!

1 Like

: D Great to see the cow’s getting out and about!

You’ll want to follow this syntax for calling to external canisters at the moment: Calling another canister's methods - #2 by Ori

Where you define the canister as an actor with a matching signature to the canister you’re calling (or subtype of). You can find the signature on its listing:

So for cowsay you can build the call as follows:

actor {
    public func main() : async Text {
        let cowsay = actor(“7igbu-3qaaa-aaaaa-qaapq-cai”): actor { cowsay: (Text) -> async Text };
        return await cowsay.cowsay(“hello”);

And a Motoko playground example is here for you:


The vision was always that you could just write

import CowSay "ic:7igbu-3qaaa-aaaaa-qaapq-cai";

in your Motoko file, and the development tools would do the rest for you (in particular, fetch that canister’s Candid file to find out the type of CowSay), but this feature never had highest priority, would have required cross-component coordination (moc and dfx, maybe replica) and there were opiniated differences on how to best do that under the hood, so it never happened. But the work-around pointed out by Ori is good enough™ for many cases.

(In fact, the Motoko compiler in moc already implements all that’s needed, as specified here. So the Motoko playground and/or dfx could add that feature on their side, and it would “just work”.)

1 Like

Thank you, Ori.
I didn’t know it was already up. I should have done a little more searching. It worked.

1 Like

I see, it doesn’t work with javascript templates for importing. Thanks a lot.