C++ WASM contracts¶
Studio compiles freestanding C++ into WebAssembly using clang. The contract uses the injected pqwerai.h
header for storage, calldata, events and calls; it does not link a C++ standard library or a WASI runtime.
Compiler setup¶
The checked-in Windows toolchain pin is wasi-sdk 34, clang 23.1.0. Extract the complete SDK and choose
its bin/clang++.exe in Studio. Keep the directory intact: the compiler also needs its linker and headers.
The wallet does not install this large SDK through its normal in-app compiler download flow.
The executable matching this pin reports clang version 23.1.0-rc3.
Studio's reviewed archive SHA-256 is
cccb5c323a9b34f0349a9b09e8804a0a7632c68c3310f4b5f437ed57d7e71d8f; its clang++.exe pin is
945cba19ec5c002628bb7d226d21a443198e5da5d9e5430fd2f61b9f143d5309.
These identify the wallet's expected Windows files, not arbitrary clang installations.
The compiler settings applied by the current adapter are:
| Setting | Purpose |
|---|---|
--target=wasm32, -O2, -nostdlib |
Compile an optimized freestanding WASM module |
-fno-exceptions, -fno-rtti |
Avoid unsupported runtime dependencies |
-mbulk-memory, -mno-reference-types, -mno-multivalue |
Select the adapter's supported feature set |
Linker --no-entry, --strip-all |
Export contract entry points without a process main function |
Linker -z,stack-size=65536 |
Reserve 64 KiB for the stack |
Linker --initial-memory=131072, --max-memory=131072 |
Fix linear memory at 128 KiB |
These are settings, not a standalone build command. Studio adds its SDK header, attached sources, include paths and dependency checks. Use the first-contract workflow for the complete build.
Contract structure¶
The counter source demonstrates the full structure:
#include "pqwerai.h"exposespqw_*host functions andpqw::helpers.PQW_EXPORT("call") void call()dispatches regular calls.- An optional
PQW_EXPORT("deploy") void deploy()initializes persistent state. C++ global constructors do not run; put initialization in this export. // @abicomments declare functions, events, errors and constructor parameters for the wallet.
Global variables and linear memory are temporary for each invocation. In the counter, SLOT and VALUE are
buffers; the durable count lives in the account's storage through pqw_storage_load and pqw_storage_store.
Attach more source files¶
Use Attach files or Attach folder for project sources. Studio compiles attached .cpp and .cc files
and makes attached headers available at their relative paths. Allowed system headers are stdint.h, stddef.h,
stdbool.h, limits.h, cstdint, cstddef and climits.
Includes must be literal paths to the SDK header, an allowed system header or an attached file. Absolute paths,
paths escaping the project, computed includes, #include_next, #embed and __has_include are refused.
The adapter also checks the compiler's dependency file before accepting its output.
Language limits and arithmetic¶
Use integers, explicit buffers and bounded loops. Avoid floating point, allocation that needs a runtime, exceptions, RTTI, libc calls, file access and network access. A module that compiles but imports foreign runtime functions will fail VM validation.
A Solidity ABI uint256 is a 32-byte word, not a native uint64_t. pqw::get_u64 reads only the low 64 bits.
Use the SDK's add256 and sub256 helpers and check their success result for full-width arithmetic;
inc256 wraps on overflow. Validate argument lengths, address padding and attached value as described in
ABI and host functions.
Sources at 83ff5b69f0 (project repository, not public yet): apps/pqwerai-wallet-windows/docs/STUDIO_DEVELOPER_GUIDE.md · apps/pqwerai-wallet-windows/src/PqwerAI.Wallet.Core/Studio/Toolchains.cs · apps/pqwerai-wallet-windows/src/PqwerAI.Wallet.Core/Studio/Wasm/WasmAdapters.cs · apps/pqwerai-wallet-windows/src/PqwerAI.Wallet.Core/Studio/Wasm/ContractSdk.cs · developers/examples/wasm/Counter.cpp
Found a problem? Report a documentation issue · Build testnet-20778+83ff5b69f0