# Icpp - looking for additional beta testers to build some C++ Smart Contracts

**URL:** <https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326>\
**Category:** Language Support\
**Created:** [May 30, 2023, 2:44pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326 "2023-05-30T14:44:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [May 30, 2023, 2:44pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/1 "2023-05-30T14:44:59Z")

</div>

Hi All,

We have entered a 6 week beta period during which we will build more C++ smart contracts and put things to the test. Target production release is July 17.

We just released version 2.4.0, which supports `update` calls in addition to the already supported `query` calls.

You can find a `counter` canister [here](https://github.com/icppWorld/icpp-demos/tree/main/canisters/counter):

**file: counter.cpp**

```plaintext
#include "counter.h"
#include <string>
#include "ic_api.h"

uint64_t counter{0};

void inc() {
  IC_API ic_api(false);
  counter += 1;
}

void read() {
  IC_API ic_api(false);
  ic_api.to_wire(CandidTypeNat64{counter});
}

void write() {
  IC_API ic_api(false);
  ic_api.from_wire(CandidTypeNat64{&counter});
}

// Calling a query function does NOT persist between calls. Try it out...
void inc_query() {
  IC_API ic_api(false);
  counter += 1;
}

```

**file: counter.did**

```json
service : {
  "inc": () -> ();
  "read": () -> (nat64) query;
  "write": (nat64) -> ();
  "inc_query": () -> () query;
}

```

**file: counter.h**

```plaintext
#pragma once

#include "wasm_symbol.h"

void inc() WASM_SYMBOL_EXPORTED("canister_update inc");
void read() WASM_SYMBOL_EXPORTED("canister_query read");
void write() WASM_SYMBOL_EXPORTED("canister_update write");
void inc_query() WASM_SYMBOL_EXPORTED("canister_query inc_query");

```

The code is pretty much self explanatory, but for details, see the [API Reference](https://docs.icpp.world/api-reference.html).

To get started, you can [install icpp-free](https://docs.icpp.world/installation.html#install-icpp-free).

During the beta period, we’re also experimenting with some ideas to use the IC’s unique capabilities for a Freemium style software licensing. It is not there yet though, so please just DM me, and I will ship you a `.whl` for `icpp-pro` that you can install and get access to all the good stuff that will make you super productive.

If you do not want to code anything up yourself, but have ideas or suggestions for a demo C++ Smart Contract, please comment in this thread, or just open an [issue](https://github.com/icppWorld/icpp-demos/issues).

Thank you for all the support and feedback.

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [June 2, 2023, 8:59pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/2 "2023-06-02T20:59:50Z")

</div>

Really excited about today’s 2.5.0 release.

After a lot of trial & error, we figured out how to get orthogonal persistence to work for all std containers, like vector, list, deque, map, etc.

Still a lot testing to do, but this is a big enabler for the C++ Smart Contracts we’re building.

You can check out an example [here](https://github.com/icppWorld/icpp-demos/blob/main/canisters/counter/src/counter_vec.cpp), where we control multiple counters using a CandidTypeVecNat64, which maps onto std::vector\<uint64\_t\>.

The hard part in all of this was to figure out what Orthogonal Persistence actually persists, and we found that only data that is globally managed works. So, we provide a set of functions to store & retrieve data from global storage for all the container types. The helper functions are also provided for std::string, in case you want to persist text between calls.

_FYI: Initially we thought that it was sufficient to simply store the container objects on the heap, and point to them from a global pointer, and all would be honky dory for orthogonal persistence to do it’s thing. It turned out that this does not work._  
_The update calls always work, but then during the next call, doesn’t matter if it is a query call or another update call, we get the error “IC0502: Canister trapped: unknown”._  
_I understand that this is a runtime error on the IC and usually indicates a problem with memory allocation, out-of-bounds access, or null pointer dereference. Perhaps, we’re guessing here, since the container object on the heap is managing it’s own internal dynamic memory, it is de-allocating it’s internal data storage after the call is done, and then during the next call, we get an error that the canister is no longer good if we’re trying to access memory that is no longer there._

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [June 10, 2023, 12:50am UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/3 "2023-06-10T00:50:44Z")

</div>

Just added an example how to use orthogonal persistence to store data for an authenticated caller (principal). A very common pattern…

You can find it [here](https://github.com/icppWorld/icpp-demos/blob/main/canisters/counter/src/counter_for_caller.cpp).

It requires icpp-free 2.6.0, due to a fix for the std::unordered\_map that is used.

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [June 14, 2023, 2:09am UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/4 "2023-06-14T02:09:14Z")

</div>

Finished the _capstone project_ of the grant 🥳.

One goal at the start of the project was to be able to write [this Motoko smart contract](https://github.com/web3r-chat/dapp-0/blob/main/src/backend/motoko/main.mo) in C++.

Well…, [here](https://github.com/web3r-chat/dapp-0/blob/main/src/backend/cpp/src/canister_main.cpp) it is. It requires `icpp-free 2.7.0`, which was released today.

Got the dApp with this C++ backend deployed to the IC, and I am ready for the final review with the Grant committee tomorrow 🤞

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [July 5, 2023, 8:10pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/5 "2023-07-05T20:10:19Z")

</div>

Hey! Is icpp open source? I’m looking for the repo. I’d like to open an issue/start a discussion around conventions for some cdk Wasm metadata so that we can track cdk stats live on the IC.

You can see what I’m suggesting here: [cdk wasm public metadata · Issue #410 · dfinity/cdk-rs · GitHub](https://github.com/dfinity/cdk-rs/issues/410)

Happy to discuss elsewhere.

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [July 5, 2023, 8:49pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/6 "2023-07-05T20:49:42Z")

</div>

Hi @lastmjs ,  
It is mostly open source under MIT license, and you can find it here.

> **[GitHub - icppWorld/icpp-free: A development platform for C++ smart contracts...](https://github.com/icppWorld/icpp-free)**
>
> A development platform for C++ smart contracts of the Internet Computer - GitHub - icppWorld/icpp-free: A development platform for C++ smart contracts of the Internet Computer

I will check out your link, but yes, any issue or initiation of discussion in that repo are highly appreciated.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [July 5, 2023, 8:52pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/7 "2023-07-05T20:52:44Z")

</div>

Great, I opened this issue: [cdk wasm public metadata · Issue #1 · icppWorld/icpp-free · GitHub](https://github.com/icppWorld/icpp-free/issues/1)

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [July 11, 2023, 8:54pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/8 "2023-07-11T20:54:18Z")

</div>

@lastmjs ,  
I had a look a the different ways this could be done, and I believe the only option in my case is to implement it as a post build step, by modifying the wasm file.

There is capability for custom sections at the LLVM level, but not at the C++ frontend level.

So, I want to use a pure python module to do the injection of the custom sections and am currently looking for the best options.

I assume you plan to use a similar approach for Kybra?

If so, have you settled yet on the python package to use for the wasm file manipulation?

Thanks in advance for your guidance!

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [July 11, 2023, 9:10pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/9 "2023-07-11T21:10:43Z")

</div>

Yes we already do this using ic-wasm to perform the manipulation during our build process.

But you should probably wait for dfx extensions and/or use the metadata section of dfx.json, see here: [gzip and metadata · Issue #1029 · demergent-labs/azle · GitHub](https://github.com/demergent-labs/azle/issues/1029)

The metadata section makes adding this functionality relatively trivial. dfx extensions will allow you to create an extension for your cdk and produce the dfx.json automatically. We’re probably a few weeks out from a beta that would allow us to test out dfx extensions.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [July 11, 2023, 9:12pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/10 "2023-07-11T21:12:02Z")

</div>

If you do want to see how we have been doing it with ic-wasm then you can check this out: [https://github.com/demergent-labs/kybra/blob/main/kybra/\_\_main\_\_.py#L378](https://github.com/demergent-labs/kybra/blob/main/kybra/ __main__.py#L378)

Things are up in the air a bit because we’re waiting on dfx extensions and some other things to make this really smooth.

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [July 11, 2023, 10:04pm UTC](https://forum.dfinity.org/t/icpp-looking-for-additional-beta-testers-to-build-some-c-smart-contracts/20326/11 "2023-07-11T22:04:43Z")

</div>

Great! I will check it out!

I want a solution that runs on Windows natively, so dfx is not an option for now, but I will have a closer look at ic-wasm and how you implemented it.
