Smart contracts on QuanChain
Channel 2 hosts the contract layer. Familiar Solidity syntax with quantum-aware primitives — composite signatures, level-gated entry points, and rotation-safe storage.
The smart-contract channel
Contract calls settle on Channel 2 with a 2-second finality budget and a 512 KB payload cap. The execution layer is a QuanChain-flavoured EVM with extensions for composite-signature verification, Merkle-proof primitives, and per-level address parsing.
EVM-compatible
Solidity 0.8.x compiles directly. Most existing tooling works after a network switch.
Quantum-aware ops
Native opcodes: VERIFYCOMPOSITE, PARSELEVEL, MERKLEVERIFY.
2s finality
Channel 2 finalises in roughly 2 seconds. Use Channel 1 for sub-second UX.
Languages and tooling
Solidity is the canonical language. A Rust-based DSL (qcr) is available for contracts that need tighter control over composite verification.
Solidity
Versions 0.8.20+ supported. Hardhat + Foundry plugins on npm under @quanchain/.
qcr (Rust DSL)
For composite-signature workflows and gas-tight loops. Beta.
Hello QuanChain
The minimum viable contract is a counter that can only be incremented by addresses at Level 10 or above.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@quanchain/contracts/QuanAddress.sol";
contract Counter {
using QuanAddress for address;
uint256 public count;
event Bump(address indexed by, uint256 newCount, uint8 level);
modifier minLevel(uint8 lvl) {
require(msg.sender.level() >= lvl, "level too low");
_;
}
function bump() external minLevel(10) {
count += 1;
emit Bump(msg.sender, count, msg.sender.level());
}
}Compile and deploy
The Hardhat plugin ships a quanchain network preset.
npm install --save-dev hardhat @quanchain/hardhat
npx hardhat init
# add 'quanchain' network in hardhat.config.ts
npx hardhat compile
npx hardhat deploy --network quanchain-testnet// hardhat.config.ts
import '@quanchain/hardhat';
export default {
solidity: '0.8.24',
networks: {
'quanchain-testnet': {
url: 'https://rpc-testnet.quanchain.ai',
accounts: [process.env.SEED!],
channel: 2,
},
},
};Composite-signed entry points
For irreversible administrative actions, gate a function behind a Level 20 composite signature. The runtime exposes VERIFYCOMPOSITE natively.
import "@quanchain/contracts/QuanComposite.sol";
contract Treasury {
using QuanComposite for bytes;
address public owner; // QC20_ parent
address public delegate;
function setDelegate(address newDelegate, bytes calldata sig) external {
bytes32 msgHash = keccak256(abi.encodePacked(newDelegate, block.chainid));
require(sig.verifyCompositeFor(owner, msgHash), "bad sig");
delegate = newDelegate;
}
}Quantum-safe storage
Storage slots that hold public keys carry the level prefix automatically. Reading an address from storage returns it parsed as a structured tuple:
import "@quanchain/contracts/QuanAddress.sol";
contract Registry {
mapping(bytes32 => address) public records;
function ownerOf(bytes32 id) external view
returns (uint8 level, bytes memory hash)
{
address a = records[id];
return (a.level(), a.hash());
}
}For large opaque blobs (e.g. compressed Merkle proofs), use Channel 3 storage and reference the blob hash from Channel 2.
Testing locally
A local devnet ships with the SDK and produces all three channels in a single process.
npx @quanchain/devnet start # starts on :8545 (chain 8453021)
npx hardhat test --network localhostSecurity checklist
- Gate irreversible actions behind composite-signed entry points.
- Validate
msg.sender.level()on functions that move value at scale. - Never store a private key or seed in contract storage — even encrypted.
- Use Channel 3 for blobs over 64 KB; reference the hash from Channel 2 contracts.
- Run the audit harness at /docs/api before mainnet deploy.