You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tesseract API Documentation - Updated for Working System
Overview
This documentation provides a comprehensive reference for interacting with the working Tesseract smart contract (TesseractSimple.vy). The API enables secure cross-rollup transaction coordination with built-in safety mechanisms.
const{ ethers }=require('ethers');constcontractABI=require('./artifacts/TesseractSimple.json').abi;// Connect to contractconstprovider=newethers.providers.JsonRpcProvider('YOUR_RPC_URL');constsigner=provider.getSigner();constcontract=newethers.Contract(CONTRACT_ADDRESS,contractABI,signer);// Buffer transactionasyncfunctionbufferTransaction(){consttxId='0x'+'01'.repeat(32);consttimestamp=Math.floor(Date.now()/1000)+300;// 5 minutes from nowconsttx=awaitcontract.buffer_transaction(txId,'0xOriginRollupAddress','0xTargetRollupAddress',ethers.utils.toUtf8Bytes('transaction payload'),'0x'+'00'.repeat(32),// No dependencytimestamp);constreceipt=awaittx.wait();console.log('Transaction buffered:',receipt.transactionHash);// Check if readyconstisReady=awaitcontract.is_transaction_ready(txId);console.log('Transaction ready:',isReady);}// Listen for eventscontract.on('TransactionBuffered',(txId,origin,target,timestamp)=>{console.log('New transaction:',txId);});contract.on('TransactionReady',(txId)=>{console.log('Transaction ready:',txId);});
Cross-Rollup Coordination Example
# Multi-chain coordination exampleimporttimefromweb3importWeb3# Setup contracts on different networksethereum_w3=Web3(Web3.HTTPProvider('ETHEREUM_RPC'))
polygon_w3=Web3(Web3.HTTPProvider('POLYGON_RPC'))
ethereum_contract=ethereum_w3.eth.contract(address=ETH_CONTRACT, abi=ABI)
polygon_contract=polygon_w3.eth.contract(address=POLYGON_CONTRACT, abi=ABI)
# Step 1: Buffer transaction on origin (Ethereum)tx_id=b'\x01'*32execution_time=int(time.time()) +60# 1 minute from noweth_tx=ethereum_contract.functions.buffer_transaction(
tx_id,
ethereum_contract.address, # Origin rolluppolygon_contract.address, # Target rollupb"cross-chain payload",
b'\x00'*32, # No dependencyexecution_time
).transact({'from': operator_address})
print(f"Buffered on Ethereum: {eth_tx}")
# Step 2: Resolve dependencies when readytime.sleep(65) # Wait for execution timeresolve_tx=ethereum_contract.functions.resolve_dependency(tx_id).transact({'from': operator_address})
print(f"Dependencies resolved: {resolve_tx}")
# Step 3: Check if ready for executionis_ready=ethereum_contract.functions.is_transaction_ready(tx_id).call()
print(f"Ready for execution: {is_ready}")
# Step 4: Execute on target rollup (this would be done by target rollup)ifis_ready:
# Target rollup would read the transaction details and executedetails=ethereum_contract.functions.get_transaction_details(tx_id).call()
origin, target, dependency, timestamp, state=details# Mark as executedexecuted_tx=ethereum_contract.functions.mark_executed(tx_id).transact({'from': operator_address})
print(f"Marked as executed: {executed_tx}")
Gas Optimization
Gas Estimates
Operation
Gas Usage
Notes
buffer_transaction
~80,000
Base transaction buffering
resolve_dependency
~40,000
Dependency resolution
mark_executed
~25,000
State update only
add_operator
~25,000
One-time operator setup
set_coordination_window
~25,000
Configuration change
Optimization Tips
Batch multiple dependency resolutions in application layer
Use appropriate gas limits to avoid failures
Monitor gas prices for optimal transaction timing
Security Considerations
Access Control
All transaction operations require operator authorization
Owner-only functions for administrative tasks
No external contracts can directly manipulate state
Input Validation
Transaction IDs must be unique and non-empty
Payload size limited to 512 bytes
Timestamp validation prevents past transactions
Origin/target rollup validation
State Management
Clear state transitions (EMPTY → BUFFERED → READY → EXECUTED)
Immutable transaction data once buffered
Dependency resolution with expiration handling
Testing
Compilation Test
# Test contract compilation
poetry run python scripts/test_compilation.py
# Expected output:# Compilation successful!# Bytecode length: 7,276 bytes# ABI functions: 18 items
# Local deployment (requires local node)
poetry run python scripts/deploy_simple.py
# Testnet deployment (configure RPC and private key)# Modify deploy_simple.py with testnet settings
poetry run python scripts/deploy_simple.py