# When is Cycles deducted?

**URL:** <https://forum.dfinity.org/t/when-is-cycles-deducted/35098>\
**Category:** Developers\
**Tags:** rust\
**Created:** [September 13, 2024, 6:18am UTC](https://forum.dfinity.org/t/when-is-cycles-deducted/35098 "2024-09-13T06:18:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Buriburizaemon](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/buriburizaemon/32/19925_2.png) [@Buriburizaemon](https://forum.dfinity.org/u/Buriburizaemon)\
**Post date:** [September 13, 2024, 6:18am UTC](https://forum.dfinity.org/t/when-is-cycles-deducted/35098/1 "2024-09-13T06:18:29Z")

</div>

I learned that If I end the call using `ic_cdk::trap(msg)`, cycles aren’t deducted.  
Is the case same when I’m perform cross canister call, http outcalls before calling the `trap`?  
Will the cycles be deducted?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [September 13, 2024, 8:00am UTC](https://forum.dfinity.org/t/when-is-cycles-deducted/35098/2 "2024-09-13T08:00:35Z")

</div>

`trap` rolls everything (including cycles accepted, attached to calls, …) back to the last commit point (read: `await`).

From the [docs](https://internetcomputer.org/docs/current/developer-docs/smart-contracts/maintain/trapping) (can recommend you read the full page):

> In particular, any state changes made by the canister before making the inter-canister call and calling `await` to wait for the response will not be rolled back (as this was a separate message execution that happened before the callback handler was invoked).

---

<div class="post-metadata">

**Author:** ![Buriburizaemon](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/buriburizaemon/32/19925_2.png) [@Buriburizaemon](https://forum.dfinity.org/u/Buriburizaemon)\
**Post date:** [September 13, 2024, 2:27pm UTC](https://forum.dfinity.org/t/when-is-cycles-deducted/35098/3 "2024-09-13T14:27:26Z")

</div>

thank you @Vivienne for sharing, I read it. still had some confusion.  
Can you clear this?

```rust
let res = ic_cdk::call(canister, "method", ()).await;
if let Err(e) = res{
  ic_cdk::trap("")
}

```

In this code, cycles will be deducted right?  
If it is deducted will it be cycles for calling update method, cycles for inter canister call. am I right?

---

<div class="post-metadata">

**Author:** ![Vivienne](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/vivienne/32/29170_2.png) [@Vivienne](https://forum.dfinity.org/u/Vivienne)\
**Post date:** [September 16, 2024, 6:50am UTC](https://forum.dfinity.org/t/when-is-cycles-deducted/35098/4 "2024-09-16T06:50:13Z")

</div>

Yes, that’s right. And if you attach cycles to the call then those will stay with the target canister (assuming it accepts the cycles).
