Skip to main content

Crate truthlinked_sdk

Crate truthlinked_sdk 

Source
Expand description

TruthLinked Smart Contract SDK

This SDK provides a complete toolkit for building smart contracts on the TruthLinked blockchain.

§Features

  • Storage: Type-safe collections (maps, vectors, blobs) with dual API pattern
  • Codec: Efficient encoding/decoding for 32-byte and variable-length data
  • Events: Structured logging with indexed topics
  • Manifests: Declare storage access patterns for parallel execution
  • Oracle: HTTP requests for external data
  • Testing: In-memory storage harness for unit tests

§Quick Start

use truthlinked_sdk::prelude::*;

#[derive(Manifest)]
struct Counter {
    #[manifest(read, write)]
    value: Slot,
}

fn increment() -> Result<()> {
    let counter = Counter {
        value: Slot::from_label("count"),
    };
    let current = counter.value.read_u64()?;
    counter.value.write_u64(current + 1)?;
    Ok(())
}

contract_entry!(increment);

§Module Overview

  • abi - Function selectors and calldata parsing
  • backend - Storage backend abstraction
  • call - Cross-contract calls
  • codec - Encoding/decoding traits and builders
  • collections - StorageMap, StorageVec, StorageBlob
  • context - Execution context (caller, height, timestamp, etc.)
  • [env] - Low-level WASM host bindings
  • error - Error types and Result alias
  • hashing - Cryptographic utilities
  • log - Event system
  • manifest - Storage access declarations
  • oracle - HTTP oracle interface
  • storage - Direct storage slot access
  • [testing] - Unit test utilities

Re-exports§

pub use error::Error;
pub use error::Result;

Modules§

abi
ABI (Application Binary Interface) helpers for function dispatch and calldata parsing.
backend
Storage backend abstraction for contract state persistence.
call
Cross-contract call utilities for contract composability.
codec
Serialization and deserialization traits and utilities.
collections
High-level storage collections built on 32-byte slots.
context
Execution context accessors for contract runtime information.
env
Low-level WASM host environment bindings.
error
Error handling types and utilities for contract execution.
hashing
Cryptographic hashing utilities.
log
Event logging system for smart contracts.
manifest
Contract manifest generation for parallel execution optimization.
oracle
HTTP oracle interface for external data access.
prelude
Prelude module with commonly used imports.
storage
Storage slot abstraction for direct storage access.

Macros§

contract_entry
Defines the contract entry point.
slot
Macro for creating a Slot from a 32-byte array.

Attribute Macros§

error_code
Attribute macro for defining error code enums.
require
Attribute macro for adding precondition checks to functions.

Derive Macros§

BytesCodec
Derives the BytesCodec trait for variable-length encoding.
Codec32
Derives the Codec32 trait for 32-byte fixed-size encoding.
Event
Derives the Event trait for structured logging.
Manifest
Derives the Manifest trait for storage access declarations.