Layer 2 Chain Anchoring¶
PrimeStamp supports several Ethereum Layer 2 (L2) networks for low-cost, fast blockchain anchoring. L2 chains inherit security from Ethereum while offering dramatically lower fees and faster confirmation times.
Supported L2 Chains¶
| Chain | Module | Chain ID (Mainnet) | Avg Cost | Confirmation |
|---|---|---|---|---|
| Polygon | primestamp.anchors.polygon |
137 | ~$0.001 | ~10 seconds |
| Arbitrum | primestamp.anchors.arbitrum |
42161 | ~$0.001 | ~1 second |
| Optimism | primestamp.anchors.optimism |
10 | ~$0.001 | ~2 seconds |
| Base | primestamp.anchors.base |
8453 | ~$0.001 | ~2 seconds |
| StarkNet | primestamp.anchors.starknet |
SN_MAIN | ~$0.005 | ~minutes |
| Linea | primestamp.anchors.linea |
59144 | ~$0.001 | ~seconds |
All L2 adapters are registered as plugins via the primestamp.anchors entry point group.
Trust Weight¶
L2 anchors carry a trust weight of 0.7. This is lower than L1 chains because:
- L2s derive security from their parent chain rather than running independent consensus
- Sequencer centralization can affect liveness (though not safety)
- Fraud/validity proof windows mean L2 finality takes longer to settle on L1
For high-stakes documents, combine an L2 anchor with an L1 anchor (Bitcoin or Ethereum) to achieve a higher trust score.
Polygon¶
Polygon is one of the most widely used L2 networks with extremely low and stable gas prices.
Configuration¶
from primestamp.anchors.polygon import PolygonAnchorPlugin
plugin = PolygonAnchorPlugin(config={
"network": "mainnet", # or "amoy" for testnet
"private_key": "0xYOUR_KEY",
"rpc_url": None, # uses public RPC by default
"alchemy_key": "YOUR_KEY", # optional: Alchemy for better reliability
"infura_key": "YOUR_KEY", # optional: Infura
"required_confirmations": 5,
})
await plugin.initialize()
Submitting and Verifying¶
# Submit
result = await plugin.submit(
document_hash="sha3-256:abc123...",
metadata={"filename": "report.pdf"},
)
print(f"TX: {result.transaction_id}")
print(f"Explorer: {result.metadata['explorer_url']}")
# Wait for confirmation
confirmed = await plugin.wait_for_confirmation(
result.transaction_id,
timeout=300,
)
# Verify
verification = await plugin.verify(
transaction_id=result.transaction_id,
expected_hash="sha3-256:abc123...",
)
print(f"Verified: {verification.success}")
Cost Estimation¶
# Estimate without a wallet
from primestamp.anchors.polygon import estimate_polygon_cost
estimate = estimate_polygon_cost()
# {
# "gas_limit": 50000,
# "typical_gas_price_gwei": 30,
# "estimated_cost_matic": "0.0015",
# "estimated_cost_usd": "0.00075",
# }
# Or with a connected client
estimate = await plugin.estimate_cost("sha3-256:abc123...")
Networks¶
| Network | Chain ID | Explorer |
|---|---|---|
| Polygon Mainnet | 137 | polygonscan.com |
| Polygon Amoy (testnet) | 88002 | amoy.polygonscan.com |
Arbitrum¶
Arbitrum uses optimistic rollups with ~1 second block times on its L2. Transactions are batched and posted to Ethereum for final settlement.
from primestamp.anchors.arbitrum import ArbitrumAnchorPlugin
plugin = ArbitrumAnchorPlugin(config={
"network": "mainnet",
"private_key": "0xYOUR_KEY",
})
await plugin.initialize()
result = await plugin.submit(document_hash)
Optimism¶
Optimism uses the OP Stack with EVM equivalence. Transactions feel like regular Ethereum transactions but settle at a fraction of the cost.
from primestamp.anchors.optimism import OptimismAnchorPlugin
plugin = OptimismAnchorPlugin(config={
"network": "mainnet",
"private_key": "0xYOUR_KEY",
})
await plugin.initialize()
result = await plugin.submit(document_hash)
Base¶
Base is built on the OP Stack and backed by Coinbase. It offers the same low costs as Optimism with strong institutional adoption.
from primestamp.anchors.base import BaseAnchorPlugin
plugin = BaseAnchorPlugin(config={
"network": "mainnet",
"private_key": "0xYOUR_KEY",
})
await plugin.initialize()
result = await plugin.submit(document_hash)
StarkNet¶
StarkNet uses zero-knowledge (validity) proofs rather than optimistic rollups. This means transactions are mathematically proven correct rather than assumed correct with a challenge period. StarkNet costs are slightly higher due to proof generation but provide stronger guarantees.
from primestamp.anchors.starknet import StarkNetAnchorPlugin
plugin = StarkNetAnchorPlugin(config={
"network": "mainnet",
"private_key": "YOUR_STARK_KEY",
})
await plugin.initialize()
result = await plugin.submit(document_hash)
Linea¶
Linea is a zkEVM L2 by Consensys. It is fully EVM-compatible and uses zero-knowledge proofs for settlement.
from primestamp.anchors.linea import LineaAnchorPlugin
plugin = LineaAnchorPlugin(config={
"network": "mainnet",
"private_key": "0xYOUR_KEY",
})
await plugin.initialize()
result = await plugin.submit(document_hash)
Choosing an L2¶
| Use Case | Recommended L2 | Reason |
|---|---|---|
| Lowest cost | Polygon, Arbitrum, Base | Consistently sub-cent fees |
| Fastest confirmation | Arbitrum | ~1 second block time |
| Strongest proof | StarkNet | ZK validity proofs |
| Institutional trust | Base | Coinbase backing, regulatory clarity |
| Widest ecosystem | Polygon | Largest L2 user base |
| EVM equivalence | Optimism, Base | OP Stack identical to Ethereum |
Combining L2 with L1¶
A common pattern is to use an L2 for fast initial confirmation and Bitcoin for long-term archival:
from primestamp.anchors.adapters import create_anchor_manager
from primestamp.anchors.polygon import PolygonAnchorPlugin
# L1 anchors via the standard manager
manager = create_anchor_manager()
# Add Polygon as an L2 anchor
polygon = PolygonAnchorPlugin(config={"private_key": "0xKEY"})
await polygon.initialize()
# Submit to both
l1_results = await manager.submit(hash_bytes, [AnchorType.BITCOIN, AnchorType.RFC3161])
l2_result = await polygon.submit(hash_hex)
# Fast confirmation from Polygon (~10s)
# Strong archival proof from Bitcoin (~1h)
Plugin Development¶
To add support for a new L2, create a class extending AnchorPlugin and register it in pyproject.toml:
The plugin must implement submit(), verify(), and get_status() async methods.