blockchain-basics
Master blockchain fundamentals including consensus, cryptography, and distributed systems
What this skill does
# Blockchain Basics Skill
> Master blockchain fundamentals including consensus mechanisms, cryptographic primitives, and distributed systems architecture.
## Quick Start
```python
# Invoke this skill for blockchain fundamentals
Skill("blockchain-basics", topic="consensus", depth="intermediate")
```
## Topics Covered
### 1. Consensus Mechanisms
Learn how distributed networks achieve agreement:
- **Proof of Work**: Mining, hashrate, difficulty adjustment
- **Proof of Stake**: Validators, slashing, finality
- **Byzantine Fault Tolerance**: Leader election, view changes
### 2. Cryptographic Foundations
Understand the security primitives:
- **Hash Functions**: SHA-256, Keccak-256, properties
- **Digital Signatures**: ECDSA, Ed25519, verification
- **Merkle Trees**: Proof construction, verification
### 3. Network Architecture
Explore distributed systems:
- **P2P Networks**: Gossip protocols, peer discovery
- **Node Types**: Full nodes, light clients, archives
- **Block Propagation**: Compact blocks, relay networks
### 4. Transaction Lifecycle
Follow data through the chain:
- **Transaction Structure**: Inputs, outputs, signatures
- **Mempool**: Fee markets, ordering, priority
- **Confirmation**: Finality, reorganization
## Code Examples
### Verify Merkle Proof
```python
import hashlib
def verify_merkle_proof(leaf: bytes, proof: list, root: bytes) -> bool:
"""Verify a Merkle proof for inclusion"""
current = leaf
for sibling, is_left in proof:
if is_left:
current = hashlib.sha256(sibling + current).digest()
else:
current = hashlib.sha256(current + sibling).digest()
return current == root
```
### Calculate Block Hash
```python
import hashlib
import struct
def calculate_block_hash(header: dict) -> bytes:
"""Calculate Bitcoin-style block hash"""
data = struct.pack(
'<I32s32sIII',
header['version'],
bytes.fromhex(header['prev_block']),
bytes.fromhex(header['merkle_root']),
header['timestamp'],
header['bits'],
header['nonce']
)
return hashlib.sha256(hashlib.sha256(data).digest()).digest()[::-1]
```
## Common Pitfalls
| Pitfall | Issue | Solution |
|---------|-------|----------|
| Finality confusion | PoW is probabilistic | Wait for 6+ confirmations |
| Hash vs encryption | Hashes are one-way | Use proper encryption for secrets |
| Timestamp trust | Miners can manipulate | Use block height for precision |
## Troubleshooting
### "Why is my transaction not confirming?"
1. Check transaction fee vs current mempool
2. Verify nonce is sequential (no gaps)
3. Ensure sufficient balance for amount + gas
### "How do I verify a signature?"
```python
from eth_account import Account
from eth_account.messages import encode_defunct
message = encode_defunct(text="Hello")
address = Account.recover_message(message, signature=sig)
```
## Learning Path
```
[Beginner] → Hash Functions → Digital Signatures → Transactions
↓
[Intermediate] → Merkle Trees → Consensus → Network Layer
↓
[Advanced] → BFT Protocols → Sharding → Cross-chain
```
## Test Yourself
```python
# Unit test template
def test_merkle_root():
txs = [b"tx1", b"tx2", b"tx3", b"tx4"]
root = build_merkle_root(txs)
assert len(root) == 32
assert verify_merkle_proof(txs[0], get_proof(0), root)
```
## Cross-References
- **Bonded Agent**: `01-blockchain-fundamentals`
- **Related Skills**: `ethereum-development`, `smart-contract-security`
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 2.0.0 | 2025-01 | Production-grade with validation, examples |
| 1.0.0 | 2024-12 | Initial release |
Related in Web3
xaut-trade
IncludedBuy or sell XAUT (Tether Gold) on Ethereum. Supports market orders (Uniswap V3) and limit orders (UniswapX). Wallet modes: Foundry keystore or WDK. Delegates non-XAUT intents to registered skills (e.g. Polymarket prediction markets, Hyperliquid trading). Triggers: buy XAUT, XAUT trade, swap USDT for XAUT, sell XAUT, swap XAUT for USDT, limit order, limit buy XAUT, limit sell XAUT, check limit order, cancel limit order, XAUT when, create wallet, setup wallet, polymarket, prediction market, bet on, odds on, hyperliquid, perp, perpetual, long, short, open long, open short, close position, leverage.
qfc-openclaw-skill
IncludedQFC blockchain interaction — wallet, faucet, chain queries, staking, epoch & finality, AI inference
gate-dex-trade
IncludedExecutes on-chain token swaps via Gate DEX. Use when user wants to swap, buy, sell, exchange, or convert tokens, or bridge cross-chain. Covers full swap flow: price quotes, transaction build, signing, and submission. Do NOT use for read-only data lookups or wallet account management.
hunch
IncludedDiscover, bet on, track, and settle Hunch prediction markets in natural language. Trigger when a user wants to bet, take a position, or get odds on a crypto outcome — token market-cap milestones and flips, launchpad races (Bankr vs pump.fun volume / #1-days / launches over a cap), token head-to-head outperformance, mcap strike-ladders, and up/down price rounds. Also trigger on "what can I bet on about $TOKEN", "odds on …", "take YES/NO on …", "show my Hunch bets", "did my market resolve". Settles in USDC on Base via x402 (≤ $10 / bet); every bet returns an on-chain proof.
opensea
IncludedQuery NFT data, trade on the Seaport marketplace, and swap ERC20 tokens across Ethereum, Base, Arbitrum, Optimism, Polygon, and more.
polymarket
IncludedTrade on Polymarket prediction markets (CLOB V2) from a Privy EOA wallet. Search markets, place/cancel orders, manage positions. No private key handling. Use when the user wants to bet on event outcomes (e.g. "buy YES at 0.65 on the ceasefire market", "what are my open positions", "close my Trump bet").