# Careful Onboarding

<mark style="color:red;">**Don't: Do not call**</mark> <mark style="color:red;">`onBoard`</mark> <mark style="color:red;">**on a value that has not previously had**</mark> <mark style="color:red;">`offBoard`</mark> <mark style="color:red;">**called on it**</mark>

```solidity
contract BadContract {
  ctUint64 public sum;
  //...
  function addWithoutCarefulOnboard() public {
    gtUint64 a = MpcCore.setPublic64(1);
    gtUint64 sum_ = MpcCore.onBoard(sum); // THIS WILL REVERT
   
    sum_ = MpcCore.add(sum_, a);
    
    sum = MpcCore.offBoard(sum_);
  }
  //...
}
```

<mark style="color:blue;">**Do:**</mark> <mark style="color:blue;">Initialize the value by calling</mark> <mark style="color:blue;">`offBoard`</mark> <mark style="color:blue;">inside the constructor</mark>

```solidity
contract GoodContract {
  ctUint64 public sum;
  
  constructor() {
    // By initializing sum with an encrypted value, we ensure
    // calling onBoard on sum does not revert
    gtUint64 sum_ = MpcCore.setPublic64(0);
    sum = MpcCore.offBoard(sum_);
  }
  //...
  function add() public {
    gtUint64 a = MpcCore.setPublic64(1);
    gtUint64 sum_ = MpcCore.onBoard(sum);
   
    sum_ = MpcCore.add(sum_, a);
    
    sum = MpcCore.offBoard(sum_);
  }
  //...
}
```

<mark style="color:blue;">**Or:**</mark> <mark style="color:blue;">Check if the value is zero before calling</mark> <mark style="color:blue;">`onBoard`</mark>

<pre class="language-solidity"><code class="lang-solidity"><strong>contract GoodContract {
</strong>  ctUint64 public sum;
  //...
  function addWithCarefulOnboard() public {
    gtUint64 a = MpcCore.setPublic64(1);
    gtUint64 sum_;
    
    // By checking if sum is equal to zero, we can verify whether
    // or not it is safe to call onBoard on sum
    if (ctUint64.unwrap(sum) == 0) {
        sum_ = MpcCore.setPublic64(0);
    } else {
        sum_ = MpcCore.onBoard(sum);
    }
   
    sum_ = MpcCore.add(sum_, a);
    
    sum = MpcCore.offBoard(sum_);
  }
  //...
}
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coti.io/coti-documentation/build-on-coti/guides/best-practices/careful-onboarding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
