Ashen SDK
The Ashen SDK provides Zig modules for writing smart contracts that run on Ashen’s RISC-V execution environment.
Quick Start
Section titled “Quick Start”const sdk = @import("ashen-sdk");
export fn _start(calldata_ptr: [*]const u8, calldata_len: usize) sdk.ByteSlice { sdk.heap.reset(); const calldata = if (calldata_len == 0) &[_]u8{} else calldata_ptr[0..calldata_len]; // Your contract logic here return sdk.ByteSlice.from(result);}
pub const panic = sdk.panic;Modules
Section titled “Modules”sdk.storage - Persistent key-value storage
const storage = sdk.storage;
// Read/write raw bytesconst value = storage.read(key);storage.write(key, data);
// Typed helpers for u128const balance = storage.readU128(key);storage.writeU128(key, amount);sdk.context - Block and transaction context
const ctx = sdk.context;
const sender = ctx.caller(); // Immediate callerconst tx_origin = ctx.origin(); // Transaction originatorconst height = ctx.blockHeight();const attached = ctx.value(); // Attached valuesdk.crypto - Hash functions
const crypto = sdk.crypto;
const k_hash = crypto.keccak256(data);const s_hash = crypto.sha256(data);const b_hash = crypto.blake3(data);sdk.events - Typed event emission
const events = sdk.events;
// Define event signatureconst Transfer = events.define("Transfer(address,address,uint256)");
// Emit with indexed topicsTransfer.emit2(from, to, events.toTopicU128(amount), &[_]u8{});sdk.math - Fixed-point arithmetic
const math = sdk.math;
const shares = math.isqrt(product); // Integer sqrtconst fee = math.bpsMul(amount, 30); // 0.3% (30 bps)const smaller = math.min(u128, a, b);const larger = math.max(u128, a, b);sdk.guards - Safety utilities
const guards = sdk.guards;
// Reentrancy protectiontry guards.enterNonReentrant();defer guards.exitNonReentrant();
// Safe arithmetic (returns error on overflow)const sum = guards.safeAdd(u128, a, b) catch return error;const diff = guards.safeSub(u128, a, b) catch return error;Module Reference
Section titled “Module Reference”| Module | Import | Purpose |
|---|---|---|
heap | sdk.heap | Bump allocator |
storage | sdk.storage | State read/write |
context | sdk.context | Caller, origin, block info |
crypto | sdk.crypto | Keccak256, SHA256, Blake3 |
events | sdk.events | Event emission |
guards | sdk.guards | Reentrancy, safe math |
math | sdk.math | WAD/RAY/BPS math |
Next Steps
Section titled “Next Steps” Zig Guide Detailed Zig contract tutorial
IDL & ABI Interface definitions
Examples Sample contracts
Deploying Deployment guide