C# WASM contracts¶
Studio uses Roslyn to compile C# to IL, then its own translator converts supported IL to WebAssembly. Validators execute the WASM module. They do not execute a DLL or start the .NET runtime.
Compiler setup¶
The Windows pin is .NET SDK 10.0.403, containing Roslyn 5.9.0-1.26523.112. Install or extract the full SDK,
then choose sdk/10.0.403/Roslyn/bincore/csc.dll in Studio. Keep the SDK's dotnet host and reference packs
alongside it; copying just csc.dll will not provide System.Runtime.dll.
The pinned Windows SDK archive SHA-256 is
f398979a9cac2dba760771c4e01f16e431dcd6bcfb2213e3e8f5b3d354095cc0; the compiler DLL pin is
f9ea6e4b51f4ac07b9005fddf3e5a0022d9d60cf95a1c404809de63ba6d0eb3b.
These are the Studio toolchain identities, not a claim about every installed SDK.
Studio supplies PqwerAI.Contracts.cs and invokes Roslyn with unsafe code, optimization and deterministic
compilation enabled. It then translates the resulting library. A successful Roslyn compilation can still fail
translation if the code uses unsupported features.
Contract structure¶
The counter source uses PqwerAI.Contracts:
| Element | Role |
|---|---|
public static unsafe class Counter |
Container for contract methods and pointer-based buffers |
[Export("call")] public static void Call() |
Regular invocation entry point |
Optional [Export("deploy")] static void method |
Initialization during creation |
Host |
Approved VM imports |
Sdk |
ABI words, selectors, literals, memory helpers and arithmetic |
// @abi comments |
Wallet-visible function, event, error and constructor declarations |
Supported C# subset¶
| Supported | Details |
|---|---|
| Static methods | Calls and recursion, subject to gas and execution bounds |
| Integers and enums | bool, byte through long/ulong, char, integer-backed enums |
| Control flow | Branches, loops, switch and integer expressions |
| Unmanaged structs | Fields, nested structs, constructors, instance methods, properties, fixed buffers, sequential and explicit layout |
| References and pointers | ref/out/in, pointer arithmetic, address-of, sizeof, stackalloc |
| Checked arithmetic | Supported overflow and division errors revert; unchecked operations wrap |
| Static fields and initializers | Reinitialized for each invocation; cyclic initializer dependencies are rejected |
| Literal intrinsics | Sdk.Utf8, Utf8Len, Hex, HexLen for compile-time literals |
The translator rejects heap objects, managed arrays, strings as runtime values, generics, exceptions and
try/catch/finally, floating point, delegates, lambdas, boxing, virtual/interface calls and calls into
.NET libraries. A static class container is supported; allocating class instances is not.
Keep literal strings in SDK intrinsics. A general string operation or library call is not made available by
adding a using statement. Attach extra .cs files for additional code written within the same subset.
Persistent state and ABI words¶
static ulong count does not persist between transactions. Use Host.StorageLoad and Host.StorageStore
with 32-byte keys and values. Static fields and stackalloc buffers are working memory only.
uint256 in the ABI is a 32-byte big-endian value. Sdk.GetU64 reads only its low 64 bits; Sdk.PutU64 writes
a zero-extended 64-bit value. For full-width arithmetic, use Sdk.AddU256 / SubU256 and handle a false result
with a revert. C# checked does not turn a ulong into a 256-bit number.
Use Sdk.RequireArgs, Sdk.ArgAddress and Sdk.RequireNoValue to enforce the interface you declare.
See ABI, storage and host functions for constructor encoding, events and cross-VM calls.
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.cs
Found a problem? Report a documentation issue · Build testnet-20778+83ff5b69f0