# Motoko - check if function is called internally

**URL:** <https://forum.dfinity.org/t/motoko-check-if-function-is-called-internally/6331>\
**Category:** Developers\
**Created:** [August 6, 2021, 3:13pm UTC](https://forum.dfinity.org/t/motoko-check-if-function-is-called-internally/6331 "2021-08-06T15:13:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehsan6sha](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ehsan6sha/32/2460_2.png) [@ehsan6sha](https://forum.dfinity.org/u/ehsan6sha)\
**Post date:** [August 6, 2021, 3:13pm UTC](https://forum.dfinity.org/t/motoko-check-if-function-is-called-internally/6331/1 "2021-08-06T15:13:23Z")

</div>

Hi  
I have a baic questio about Motoko.  
Is there a way to check if function is called internally?  
For example when a function is called by another function internally, I know that msg.caller returns canister id (for example rrkah-fqaa-aaaa-…) and I can just use and if `msg.caller == hardcoded` vaue to check if it is internll call.  
Is there a better way to do it without hardcoding?

---

<div class="post-metadata">

**Author:** ![quint](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/quint/32/40449_2.png) [@quint](https://forum.dfinity.org/u/quint)\
**Post date:** [August 6, 2021, 3:20pm UTC](https://forum.dfinity.org/t/motoko-check-if-function-is-called-internally/6331/2 "2021-08-06T15:20:46Z")

</div>

You can get the ‘internal’ canister id like this:

```auto
actor class X() = this {
  func y() {
    // cid is the canister id of this instance.
    cid = Principal.fromActor(this);
  };
}

```

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [August 7, 2021, 8:48am UTC](https://forum.dfinity.org/t/motoko-check-if-function-is-called-internally/6331/3 "2021-08-07T08:48:33Z")

</div>

And when and if [actor t \<: principal · Issue #2264 · dfinity/motoko · GitHub](https://github.com/dfinity/motoko/issues/2264) gets implemented you won’t even have to convert from actor to principal explicitly
