Skip to content
ReferenceTestnet: see pageMainnet: Not availableSoftware: Core bad4a06ea · protocol pqwerai-v8-testnet/1Updated

WASM ABI, storage and host functions

WASM contracts use the Solidity ABI. The VM enters the exported call function and your dispatcher interprets calldata. It does not automatically turn C++ or C# methods into externally callable functions.

Entry points and ABI declarations

Entry point C++ C# Calldata
Regular call PQW_EXPORT("call") void call() [Export("call")] static void method Four-byte selector, then ABI arguments
Optional initialization PQW_EXPORT("deploy") void deploy() [Export("deploy")] static void method ABI constructor arguments without a selector

Use // @abi function ..., // @abi event ..., // @abi error ... and // @abi constructor(...) comments to provide Studio's interface. A declaration such as constructor(uint256 initialSupply) adds a constructor input to the deployment form; your deploy implementation must decode and validate its raw argument bytes. The RequireArgs helpers include a four-byte selector in their size check, so they are for regular function calls, not constructor calldata.

The tutorial's selectors are 0xd09de08a for increment() and 0x6d4ce63c for get(). Return values use standard ABI words. For example, returning the integer 1 means 31 zero bytes followed by 01. Unknown selectors should revert unless you intentionally implement fallback or receive behavior.

Validate inputs explicitly

The @abi declarations describe the interface; they do not enforce view, nonpayable or argument validation.

Check C++ helper C# helper
At least n argument words after the selector pqw::require_args(n) Sdk.RequireArgs(n)
Copy an argument word pqw::arg_word(i, out32) Sdk.ArgWord(i, out32)
Address has zero upper 12 bytes pqw::arg_address(i, out32) Sdk.ArgAddress(i, out32)
Reject attached tPQAI pqw::require_no_value() Sdk.RequireNoValue()
Finish with a word pqw::return_word(word32) Sdk.ReturnWord(word32)
Finish with an ABI boolean pqw::return_bool(value) Sdk.ReturnBool(value)

Check length before copying arguments: missing calldata can read as zero. A clean ABI address check does not reject the zero address; apply your own recipient or access policy. Validate dynamic offsets, lengths, padding and bounds before reading arrays, bytes or strings. The presence of such types in an ABI does not create a dynamic decoder in the contract SDK.

Storage and memory

Storage keys and values are 32-byte words. Addresses are 20 bytes in host calls; in ABI words they occupy the low 20 bytes with 12 leading zero bytes. Contract memory is fresh for every invocation. Use persistent storage for balances, counters and ownership; use transient storage only for transaction-scoped state.

For Solidity-compatible mappings, pqw::mapping_slot(key32, slot, out32) / Sdk.MappingSlot computes keccak256(key32 || uint256(slot)). A nested mapping repeats that calculation using the first mapping's result as the next slot. Sharing a storage interface does not automatically make two contracts' layouts identical.

Host interface

All imports below belong to module pqwerai. Pointers are offsets into contract linear memory, not host addresses. The C++ header prefixes function names with pqw_; the C# SDK exposes the methods in Host. The table describes the current SDK surface, not an additional general WASI interface.

Import names C# methods Purpose and buffer shape
calldata_size, calldata_copy CalldataSize, CalldataCopy Input length; copy into destination using offset and byte count
storage_load, storage_store StorageLoad, StorageStore 32-byte key and 32-byte value
transient_load, transient_store TransientLoad, TransientStore Transaction-scoped 32-byte keys and values
caller, address, origin Caller, Address, Origin Write a 20-byte address; use caller for immediate-sender authorization
callvalue, balance CallValue, Balance Write a 32-byte amount; balance takes a 20-byte address
block_number, timestamp, chain_id, gas_left BlockNumber, Timestamp, ChainId, GasLeft Integer chain context or remaining gas; timestamp is chain context, not a wall clock
keccak256 Keccak256 Hash a byte buffer into a 32-byte destination
emit_log EmitLog Contiguous 32-byte topics, topic count, data pointer and data length
call Call 20-byte target, 32-byte value, calldata pointer/length, gas budget; returns success indicator
static_call StaticCall Target, calldata pointer/length, gas budget; returns success indicator
delegate_call DelegateCall Delegate using the current account's execution context; returns success indicator
return_data_size, return_data_copy ReturnDataSize, ReturnDataCopy Inspect and copy the previous subcall's return or revert data
finish, revert Finish, Revert End execution with returned bytes or revert bytes

Events and EVM interoperability

For a non-anonymous event, topic 0 is keccak256 of its canonical signature. The tutorial hashes Incremented(uint256) and passes that topic with a 32-byte value to emit_log. Indexed fields need their own topics; dynamic indexed values use the ABI's hash encoding. Wallets decode receipts using the declared ABI.

An EVM caller uses the WASM contract's address and ABI as it would any other contract. A WASM caller ABI-encodes the selector and arguments for the target, then invokes call or static_call, checks success and validates the return data. Calls can target either VM.

Apply checks, state updates and reentrancy protection before external interactions. Bound forwarded gas and return-data copies. Use delegate_call only with a deliberately shared layout and trusted target. Use revert to abort when a required subcall fails; do not assume a failed subcall automatically aborts its caller. Reverts roll back affected state and logs. Out-of-gas handling is part of VM execution, not a catchable C# exception.

ERC-20 contracts

Studio's C++ and C# ERC-20 examples use a (uint256 initialSupply) constructor and mint to the deployer. Their layout uses total supply in slot 0, balances in mapping slot 1 and allowances in mapping slot 2, with standard ABI functions and Transfer / Approval events. They are tutorial implementations, not OpenZeppelin libraries compiled to WASM. Review zero-address rules, overflow, authorization, allowance changes and hostile calldata before adapting them. See the ERC-20 guide for the application interface.


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/Wasm/ContractSdk.cs · apps/pqwerai-wallet-windows/src/PqwerAI.Wallet.Core/Studio/Wasm/WasmAdapters.cs · apps/pqwerai-wallet-windows/src/PqwerAI.Wallet.Core/Studio/Wasm/WasmTokens.cs · apps/pqwerai-wallet-windows/src/PqwerAI.Wallet.Core/Studio/Compilers.cs

Found a problem? Report a documentation issue · Build testnet-20778+83ff5b69f0