Skip to main content

Module abi

Module abi 

Source
Expand description

ABI (Application Binary Interface) helpers for function dispatch and calldata parsing.

This module provides utilities for:

  • Computing function selectors from names
  • Extracting selectors from calldata
  • Reading typed values from calldata at specific offsets

§Function Selectors

TruthLinked uses FNV-1a 32-bit hashing for function selectors (4 bytes). This is deterministic, no-std compatible, and provides good distribution.

§Example

use truthlinked_sdk::abi;

// Compute selector for "transfer" function
let sel = abi::selector_of("transfer");

// Parse selector from calldata
let calldata = context::calldata()?;
let selector = abi::selector(&calldata)?;

// Read arguments
let amount = abi::read_u64(&calldata, 4)?;
let recipient = abi::read_account(&calldata, 12)?;

Constants§

ERR_BAD_CALLDATA
Error code for malformed or insufficient calldata.

Functions§

read_account
Reads a 32-byte account ID from calldata at the specified byte offset.
read_u64
Reads a u64 value from calldata at the specified byte offset.
read_u128
Reads a u128 value from calldata at the specified byte offset.
selector
Extracts the 4-byte function selector from calldata.
selector_of
Computes a 4-byte function selector from a function name.