Most used ic_cdk functions

Not sure if there are any metrics on this, but I was wondering: what functions do you use the most from ic_cdk in your projects?

I’m guessing the following comes often in your codebase:

  • caller()
  • id()
  • call()
  • time()

Any other functions?

Asking for a friend who’s building something that’s not that secret anymore :wink:

2 Likes

Cycles ledger:

  • time(): all over the place
  • caller(): a bit less, but still a lot
  • call(): not at all, but we use call_with_payment128() a few times
  • id(): never. I even looked up what it does just to double-check :slightly_smiling_face:
1 Like

Thanks a lot for the feedback, Severin! It confirms time() is the next one I should tackle.

Funny enough, I use id() quite a bit since it basically acts like admin privileges in my serverless functions.

If any other functions come to mind, feel free to share!

1 Like

In my code, there’s no doubt that caller() is used the most, since it’s heavily involved in access control.
In places where there’s a lot of state management involved, I find trap() more convenient than restoring the state step by step :rofl:

1 Like

Absolutely, caller() will definitely be useful when I extend support to allow developers to write their own endpoints (which they can already do in Rust, but not in the first iteration of the TypeScript support I’m currently wrapping up).

I also use trap() for convenience, and I’ll need to add it in the same context — good point. :+1:

Thanks for the feedback!

1 Like

:white_check_mark: id()
:white_check_mark: call()
:white_check_mark: time()
:white_check_mark: print() (used within console.log)

That should do for a first version (on top of Juno’s SDK features).

2 Likes