johnalbertini14-glitch/openclaw-skills / skills/0xbreadguy/megaeth-ai-developer-skills
megaeth-developer
VerifiedEnd-to-end MegaETH development playbook (Feb 2026). Covers wallet operations, token swaps (Kyber Network), eth_sendRawTransactionSync (EIP-7966) for instant receipts, JSON-RPC batching, real-time mini-block subscriptions, storage-aware contract patterns (Solady RedBlackTreeLib), MegaEVM gas model, WebSocket keepalive, bridging from Ethereum, and debugging with mega-evme. Use when building on MegaETH, managing wallets, sending transactions, or deploying contracts.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.5 KB |
| _meta.json | config | 300 B |
| frontend-patterns.md | markdown | 6.4 KB |
| gas-model.md | markdown | 3.6 KB |
| resources.md | markdown | 5.4 KB |
| rpc-methods.md | markdown | 9.0 KB |
| security.md | markdown | 4.5 KB |
| smart-contracts.md | markdown | 10.3 KB |
| storage-optimization.md | markdown | 3.4 KB |
| testing.md | markdown | 3.8 KB |
| wallet-operations.md | markdown | 7.6 KB |
storage-optimization.md
View on GitHub# Storage Optimization
## The Problem
MegaETH charges high gas for new storage slot creation to prevent state bloat:
```
SSTORE (0 → non-zero): 2,000,000 gas × bucket_multiplier
```
The bucket multiplier scales with usage (1×, 2×, 4×, 8×...). This makes Solidity mappings with dynamic keys expensive.
## Solution 1: Solady RedBlackTreeLib
Replace Solidity mappings with [Solady's RedBlackTreeLib](https://github.com/Vectorized/solady/blob/main/src/utils/RedBlackTreeLib.sol):
```solidity
import {RedBlackTreeLib} from "solady/src/utils/RedBlackTreeLib.sol";
contract StorageOptimized {
using RedBlackTreeLib for RedBlackTreeLib.Tree;
RedBlackTreeLib.Tree private _tree;
// Tree manages contiguous storage slots [from, to)
// Insert: allocates slot at index `to`
// Remove: swap-removes with slot at `to - 1`
// Result: slots are reused, no new allocations
}
```
**Key insight:** Avoid resetting the last slot immediately — reuse it for the next insert.
**Demo available:** MegaETH engineers have a migration demo. Contact team for access.
## Solution 2: Storage Slot Reuse
Design contracts to reuse existing slots:
```solidity
// Bad: constantly allocating new slots
mapping(uint256 => uint256) public data;
function process(uint256 key, uint256 value) {
data[key] = value; // New slot each unique key
delete data[key]; // Slot freed but not reused
}
// Better: fixed-size array with circular buffer
uint256[100] public buffer;
uint256 public head;
function process(uint256 value) {
buffer[head] = value; // Reuses existing slot
head = (head + 1) % 100;
}
```
## Solution 3: ZK Compression
For apps with large state requirements:
1. Store only a hash/commitment on-chain
2. Provide pre-state + proof with each transaction
3. Contract verifies proof, applies state transition, stores new commitment
```solidity
contract ZKCompressed {
bytes32 public stateRoot;
function update(
bytes32 newRoot,
bytes calldata preState,
bytes calldata proof
) external {
require(verify(stateRoot, preState, proof), "Invalid proof");
stateRoot = newRoot; // Only 1 storage slot
}
}
```
**Trade-off:** More compute gas, much less storage gas. Good fit for MegaETH since compute is cheap.
## Solution 4: Off-Chain Storage
For large static data:
- Use IPFS/Arweave for storage
- Store content hash on-chain
- Verify in contract if needed
```solidity
contract HybridStorage {
mapping(bytes32 => bool) public verified;
function verifyData(bytes32 hash, bytes calldata data) external {
require(keccak256(data) == hash, "Hash mismatch");
verified[hash] = true;
}
}
```
## Gas Cost Reference
| Operation | Standard EVM | MegaETH |
|-----------|-------------|---------|
| SSTORE (0→non-zero) | 20,000 | 2,000,000 × multiplier |
| SSTORE (non-zero→non-zero) | 5,000 | ~100-2,100 |
| SLOAD (warm) | 100 | 100 |
| SLOAD (cold) | 2,100 | 2,100 |
## State Size Considerations
MegaETH's state trie scales to 1+ TB but storage remains a scarce resource. At $0.10 per new slot:
- 1 billion slots = 64 GB state = $100M in fees
**Future:** State rent and state expiry mechanisms planned.
## Debugging Storage Costs
Profile gas by opcode:
```bash
# Get trace
mega-evme replay <txhash> --trace --trace.output trace.json
# Profile opcodes
python trace_opcode_gas.py trace.json
```
Look for high SSTORE counts with 0→non-zero transitions.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |