Blockchain Application
Purpose
Guide smart contract development across all major blockchain platforms. Covers language selection, contract architecture, security patterns, gas optimization, deployment, and cross-contract communication. Platform-agnostic at the protocol layer; chain-specific at the language and VM layer.
Agent Protocol
Trigger
"smart contract", "solidity", "vyper", "evm", "rust smart contract", "solana contract", "anchor framework", "cardano", "plutus", "haskell contract", "cairo", "starknet", "sierra", "hardhat", "foundry", "truffle", "dapp backend", "contract deployment", "gas optimization", "contract security", "cross-contract call", "chainlink", "oracle contract", "defi contract", "nft contract", "move language", "sui contract", "aptos contract"
Input Context
- Target blockchain and VM type (EVM/SVM/eUTxO/StarkNet/MoveVM)
- Contract purpose (token/DeFi/NFT/oracle/governance/bridge)
- Upgradeability requirements (proxy/non-upgradeable/beacon)
- Security requirements (audit level, formal verification need)
- Performance constraints (gas budget, compute units, TPS needs)
- Existing dependencies (OpenZeppelin, Anchor libraries, Plutus contracts)
Output Artifact
Complete contract architecture specification: platform selection, contract design, implementation approach, testing strategy, deployment plan, security analysis.
Response Format
- Platform selection: chain type + VM + language + framework + toolchain
- Contract architecture: entry points, storage layout, external dependencies, upgradeability
- Implementation: key functions with gas considerations and security annotations
- Testing strategy: unit, integration, fuzz, invariant, testnet deployment
- Deployment: constructor args, verification, proxy setup, multi-sig ownership
- Risk analysis: known vulnerabilities specific to this platform/pattern
Completion Criteria
- Contract architecture follows platform best practices (checks-effects-interactions, access control)
- Storage layout compatible with upgradeability pattern (if upgradeable)
- Gas optimization applied: storage reads minimized, calldata over memory where possible
- Security review covers platform-specific attack vectors (reentrancy, oracle manipulation, flash loans)
- Deployment plan includes verification, multi-sig ownership, and monitoring
Max Response Length
5000 tokens
Decision Trees
Platform Selection
Smart contract platform:
├── Need EVM compatibility?
│ ├── YES → Solidity or Vyper
│ │ ├── Solidity: EVM chains (Ethereum, Polygon, Arbitrum, Optimism, Base, BSC)
│ │ │ ├── Toolchain: Foundry (default), Hardhat (complex workflows)
│ │ │ └── Libraries: OpenZeppelin, Solady
│ │ └── Vyper: Simple contracts, audit-friendliness prioritized
│ │ └── Toolchain: ape, brownie
│ ├── NO → Evaluate non-EVM chains
│ │ ├── Solana → Rust + Anchor framework
│ │ │ └── Toolchain: Anchor CLI, Solana CLI
│ │ ├── Cardano → Haskell (Plutus) or Aiken
│ │ │ └── Toolchain: Plutus Tx, cardano-cli
│ │ ├── StarkNet → Cairo
│ │ │ └── Toolchain: Scarb, Starkli
│ │ ├── Sui/Aptos → Move
│ │ │ └── Toolchain: sui CLI / aptos CLI
│ │ └── NEAR/Polkadot → Rust (ink!)
│ │ └── Toolchain: cargo-contract
│ └── Cross-chain? → Consider platform-agnostic architecture
│ └── Abstract core logic, deploy adapters per chain
Upgradeability Decision
Need upgradeable contract?
├── YES:
│ ├── UUPS → Default for new projects (gas-efficient, clean storage)
│ ├── Transparent → Legacy projects, many upgrade functions
│ └── Beacon → Many child contracts (ERC-1167 clones)
├── NO → Immutable contract
│ └── Better security posture, no upgrade governance overhead
└── Hybrid → Immutable core + upgradeable periphery
Architecture Patterns
Checks-Effects-Interactions (Mandatory)
function withdraw(uint256 amount) external {
// 1. CHECKS: validate conditions
require(balanceOf[msg.sender] >= amount, "insufficient balance");
// 2. EFFECTS: update state first
balanceOf[msg.sender] -= amount;
// 3. INTERACTIONS: external calls last
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok, "transfer failed");
}
Access Control Patterns
- Ownable: Single owner, simplest model
- Roles (OpenZeppelin AccessControl): DEFAULT_ADMIN_ROLE + specific roles (MINTER_ROLE, PAUSER_ROLE)
- Timelock: All sensitive operations delayed by 48h-7d
- Multi-sig: M-of-N signers for admin operations
Solidity Gas Optimization Patterns
// BAD: reads storage repeatedly
function sum() external view returns (uint) {
uint total = 0;
for (uint i = 0; i < arr.length; i++) {
total += arr[i]; // SLOAD every iteration
}
return total;
}
// GOOD: cache array length and use unchecked
function sum() external view returns (uint) {
uint len = arr.length;
uint total = 0;
for (uint i = 0; i < len; i++) {
unchecked { total += arr[i]; }
}
return total;
}
Cross-Contract Communication
EVM:
├── Direct call: Interface(target).function(args) — simple, synchronous
├── Delegatecall: Proxy pattern, upgradeable storage
├── Staticcall: Read-only external call (EIP-214)
└── Low-level: address.call{value, gas}(data) — for arbitrary calls
Solana:
├── CPI (Cross-Program Invocation): invoke() or invoke_signed()
└── PDA signing: Programs sign for PDAs via invoke_signed()
Cardano:
├── Script-to-script: Redeemer-based validation
└── One-shot contracts: eUTxO model, no persistent state
Security Patterns
Common Vulnerability Mitigations
| Vulnerability |
Mitigation |
| Reentrancy |
Checks-effects-interactions, ReentrancyGuard |
| Flash loan manipulation |
TWAP pricing, min/max output constraints |
| Oracle manipulation |
Redundant oracles, stale price checks, circuit breakers |
| Frontrunning |
Commit-reveal, submarine sends, FCFS ordering |
| Signature replay |
Include chain ID, contract address, nonce in EIP-712 |
| Access control |
Timelock + multi-sig, not single admin key |
| Integer overflow |
Solidity 0.8+ built-in checks, SafeMath for older |
| Uninitialized proxy |
Constructor + disableInitializers() |
| Storage collision |
EIP-1967 structured storage, no gap variables |
Platform-Specific Patterns
EVM (Solidity)
- Storage: 32-byte slot-based, SSTORE costs 20K (cold) / 2.9K (warm)
- Events: emit for off-chain indexing, topics up to 4 (3 indexed + 1 non-indexed)
- ABI encoding: abi.encode (padded) vs abi.encodePacked (tight)
- Precompiles: ecrecover (0x01), SHA-256 (0x02), RIPEMD-160 (0x03), identity (0x04), modexp (0x05), BN254 (0x06, 0x07, 0x08), BLS12-381 (0x0a-0x0d)
Solana (Rust + Anchor)
#[derive(Accounts)]
pub struct CreateUser<'info> {
#[account(init, payer = user, space = 8 + User::INIT_SPACE)]
pub user_account: Account<'info, User>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct User {
pub name: String,
pub age: u8,
}
Cardano (Plutus)
- eUTxO model: no global state, contracts are validators
- Datum: on-chain data locked at script address
- Redeemer: spending condition
- Script context: entire transaction context available to validator
StarkNet (Cairo)
- Storage: contract-level storage variables, accessed via read()/write()
- UDC (Universal Deployer Contract): standardized contract deployment
- L1<>L2 messaging: send_message_to_l1, consume_message_from_l1
Move (Sui/Aptos)
- Resource-oriented: assets are resources, cannot be copied or dropped
- Object-centric (Sui): objects, not accounts, are the unit of storage
- Global storage (Aptos): Move modules manage access to globally stored resources
- Abilities: copy, drop, store, key — define what operations are allowed on a type
Production Considerations
Deployment Checklist
Multi-Chain Deployment
- Deterministic addresses via CREATE2 (same address on all EVM chains)
- Proxy admin same address on all chains via CREATE2
- Deployment scripts idempotent (check if already deployed)
- Cross-chain governance for upgrade coordination
- L1 as source of truth, L2 as execution layer
Gas Budget Guidelines (EVM)
- Simple transfer: 21,000 gas
- ERC-20 transfer: ~50,000 gas
- ERC-721 mint: ~100,000 gas
- Uniswap swap: ~150,000 gas
- Complex AMM operation: ~300,000 gas
- L1 block gas limit: 30M (Ethereum)
- L2 block gas limit: 30M-1B (depends on L2)
Rules
- Use Solidity for EVM chains (Ethereum, Polygon, Arbitrum, Optimism, Base, BSC)
- Use Rust for Solana (Anchor framework as default), NEAR, and Polkadot ink!
- Use Haskell/Plutus for Cardano smart contracts
- Always follow checks-effects-interactions pattern regardless of language
- Use Foundry (forge) for Solidity development and testing as default toolchain
- Include gas optimization in every code review — storage is expensive, calldata is cheaper
- Never hardcode sensitive parameters — use constructor args, setters with timelock
- Default to UUPS for upgradeable contracts over transparent proxy
- Use OpenZeppelin audited libraries over custom implementations
- Always use explicit visibility (public, external, internal, private)
- Avoid tx.origin for authentication — use msg.sender
- Validate all external inputs with require or custom errors
- Emit events for all state-changing operations
- Test on testnet with real conditions before mainnet
- Transfer ownership to multi-sig or timelock, not EOA
References
- references/blockchain-application-advanced.md — Blockchain Application Advanced Topics
- references/blockchain-application-fundamentals.md — Blockchain Application Fundamentals
- references/cairo-language.md — Cairo Language (StarkNet)
- references/contract-security.md — Smart Contract Security
- references/haskell-plutus.md — Haskell & Plutus (Cardano)
- references/move-language.md — Move Language (Sui & Aptos)
- references/rust-smart-contracts.md — Rust Smart Contracts
- references/smart-contract-patterns.md — Smart Contract Design Patterns
- references/solidity-evm.md — Solidity & EVM Deep Dive
- references/vyper-language.md — Vyper Language
- references/cross-chain-deployment.md — Cross-Chain Deployment Strategy
- references/gas-optimization-patterns.md — Gas Optimization Techniques
Phase
blockchain → blockchain-application
Handoff
blockchain-application → blockchain-testing (for test strategy implementation)
blockchain-application → blockchain-security (for pre-audit review)
Source: j4flmao/agent-skills — distributed by TomeVault.
1---2name: j4flmao-agent-skills-blockchain-application3description: Blockchain Application4---56# Blockchain Application78## Purpose9Guide smart contract development across all major blockchain platforms. Covers language selection, contract architecture, security patterns, gas optimization, deployment, and cross-contract communication. Platform-agnostic at the protocol layer; chain-specific at the language and VM layer.1011## Agent Protocol1213### Trigger14"smart contract", "solidity", "vyper", "evm", "rust smart contract", "solana contract", "anchor framework", "cardano", "plutus", "haskell contract", "cairo", "starknet", "sierra", "hardhat", "foundry", "truffle", "dapp backend", "contract deployment", "gas optimization", "contract security", "cross-contract call", "chainlink", "oracle contract", "defi contract", "nft contract", "move language", "sui contract", "aptos contract"1516### Input Context17- Target blockchain and VM type (EVM/SVM/eUTxO/StarkNet/MoveVM)18- Contract purpose (token/DeFi/NFT/oracle/governance/bridge)19- Upgradeability requirements (proxy/non-upgradeable/beacon)20- Security requirements (audit level, formal verification need)21- Performance constraints (gas budget, compute units, TPS needs)22- Existing dependencies (OpenZeppelin, Anchor libraries, Plutus contracts)2324### Output Artifact25Complete contract architecture specification: platform selection, contract design, implementation approach, testing strategy, deployment plan, security analysis.2627### Response Format281. **Platform selection**: chain type + VM + language + framework + toolchain292. **Contract architecture**: entry points, storage layout, external dependencies, upgradeability303. **Implementation**: key functions with gas considerations and security annotations314. **Testing strategy**: unit, integration, fuzz, invariant, testnet deployment325. **Deployment**: constructor args, verification, proxy setup, multi-sig ownership336. **Risk analysis**: known vulnerabilities specific to this platform/pattern3435### Completion Criteria36- Contract architecture follows platform best practices (checks-effects-interactions, access control)37- Storage layout compatible with upgradeability pattern (if upgradeable)38- Gas optimization applied: storage reads minimized, calldata over memory where possible39- Security review covers platform-specific attack vectors (reentrancy, oracle manipulation, flash loans)40- Deployment plan includes verification, multi-sig ownership, and monitoring4142### Max Response Length435000 tokens4445## Decision Trees4647### Platform Selection48```49Smart contract platform:50├── Need EVM compatibility?51│ ├── YES → Solidity or Vyper52│ │ ├── Solidity: EVM chains (Ethereum, Polygon, Arbitrum, Optimism, Base, BSC)53│ │ │ ├── Toolchain: Foundry (default), Hardhat (complex workflows)54│ │ │ └── Libraries: OpenZeppelin, Solady55│ │ └── Vyper: Simple contracts, audit-friendliness prioritized56│ │ └── Toolchain: ape, brownie57│ ├── NO → Evaluate non-EVM chains58│ │ ├── Solana → Rust + Anchor framework59│ │ │ └── Toolchain: Anchor CLI, Solana CLI60│ │ ├── Cardano → Haskell (Plutus) or Aiken61│ │ │ └── Toolchain: Plutus Tx, cardano-cli62│ │ ├── StarkNet → Cairo63│ │ │ └── Toolchain: Scarb, Starkli64│ │ ├── Sui/Aptos → Move65│ │ │ └── Toolchain: sui CLI / aptos CLI66│ │ └── NEAR/Polkadot → Rust (ink!)67│ │ └── Toolchain: cargo-contract68│ └── Cross-chain? → Consider platform-agnostic architecture69│ └── Abstract core logic, deploy adapters per chain70```7172### Upgradeability Decision73```74Need upgradeable contract?75├── YES:76│ ├── UUPS → Default for new projects (gas-efficient, clean storage)77│ ├── Transparent → Legacy projects, many upgrade functions78│ └── Beacon → Many child contracts (ERC-1167 clones)79├── NO → Immutable contract80│ └── Better security posture, no upgrade governance overhead81└── Hybrid → Immutable core + upgradeable periphery82```8384## Architecture Patterns8586### Checks-Effects-Interactions (Mandatory)87```88function withdraw(uint256 amount) external {89 // 1. CHECKS: validate conditions90 require(balanceOf[msg.sender] >= amount, "insufficient balance");9192 // 2. EFFECTS: update state first93 balanceOf[msg.sender] -= amount;9495 // 3. INTERACTIONS: external calls last96 (bool ok, ) = msg.sender.call{value: amount}("");97 require(ok, "transfer failed");98}99```100101### Access Control Patterns102- **Ownable**: Single owner, simplest model103- **Roles (OpenZeppelin AccessControl)**: DEFAULT_ADMIN_ROLE + specific roles (MINTER_ROLE, PAUSER_ROLE)104- **Timelock**: All sensitive operations delayed by 48h-7d105- **Multi-sig**: M-of-N signers for admin operations106107### Solidity Gas Optimization Patterns108```solidity109// BAD: reads storage repeatedly110function sum() external view returns (uint) {111 uint total = 0;112 for (uint i = 0; i < arr.length; i++) {113 total += arr[i]; // SLOAD every iteration114 }115 return total;116}117118// GOOD: cache array length and use unchecked119function sum() external view returns (uint) {120 uint len = arr.length;121 uint total = 0;122 for (uint i = 0; i < len; i++) {123 unchecked { total += arr[i]; }124 }125 return total;126}127```128129### Cross-Contract Communication130```131EVM:132├── Direct call: Interface(target).function(args) — simple, synchronous133├── Delegatecall: Proxy pattern, upgradeable storage134├── Staticcall: Read-only external call (EIP-214)135└── Low-level: address.call{value, gas}(data) — for arbitrary calls136137Solana:138├── CPI (Cross-Program Invocation): invoke() or invoke_signed()139└── PDA signing: Programs sign for PDAs via invoke_signed()140141Cardano:142├── Script-to-script: Redeemer-based validation143└── One-shot contracts: eUTxO model, no persistent state144```145146## Security Patterns147148### Common Vulnerability Mitigations149| Vulnerability | Mitigation |150|---|---|151| Reentrancy | Checks-effects-interactions, ReentrancyGuard |152| Flash loan manipulation | TWAP pricing, min/max output constraints |153| Oracle manipulation | Redundant oracles, stale price checks, circuit breakers |154| Frontrunning | Commit-reveal, submarine sends, FCFS ordering |155| Signature replay | Include chain ID, contract address, nonce in EIP-712 |156| Access control | Timelock + multi-sig, not single admin key |157| Integer overflow | Solidity 0.8+ built-in checks, SafeMath for older |158| Uninitialized proxy | Constructor + disableInitializers() |159| Storage collision | EIP-1967 structured storage, no gap variables |160161## Platform-Specific Patterns162163### EVM (Solidity)164- Storage: 32-byte slot-based, SSTORE costs 20K (cold) / 2.9K (warm)165- Events: emit for off-chain indexing, topics up to 4 (3 indexed + 1 non-indexed)166- ABI encoding: abi.encode (padded) vs abi.encodePacked (tight)167- Precompiles: ecrecover (0x01), SHA-256 (0x02), RIPEMD-160 (0x03), identity (0x04), modexp (0x05), BN254 (0x06, 0x07, 0x08), BLS12-381 (0x0a-0x0d)168169### Solana (Rust + Anchor)170```rust171#[derive(Accounts)]172pub struct CreateUser<'info> {173 #[account(init, payer = user, space = 8 + User::INIT_SPACE)]174 pub user_account: Account<'info, User>,175 #[account(mut)]176 pub user: Signer<'info>,177 pub system_program: Program<'info, System>,178}179180#[account]181pub struct User {182 pub name: String,183 pub age: u8,184}185```186187### Cardano (Plutus)188- eUTxO model: no global state, contracts are validators189- Datum: on-chain data locked at script address190- Redeemer: spending condition191- Script context: entire transaction context available to validator192193### StarkNet (Cairo)194- Storage: contract-level storage variables, accessed via read()/write()195- UDC (Universal Deployer Contract): standardized contract deployment196- L1<>L2 messaging: send_message_to_l1, consume_message_from_l1197198### Move (Sui/Aptos)199- Resource-oriented: assets are resources, cannot be copied or dropped200- Object-centric (Sui): objects, not accounts, are the unit of storage201- Global storage (Aptos): Move modules manage access to globally stored resources202- Abilities: copy, drop, store, key — define what operations are allowed on a type203204## Production Considerations205206### Deployment Checklist207- [ ] Constructor args verified and tested208- [ ] Proxy admin transferred to multi-sig (not deployer EOA)209- [ ] Implementation contract initialized and disabled210- [ ] Contract verified on block explorer211- [ ] Ownership transferred to timelock + governance212- [ ] Emergency pause mechanism tested213- [ ] Rate limits configured for high-value functions214- [ ] Monitoring alerts set up for suspicious activity215216### Multi-Chain Deployment217- Deterministic addresses via CREATE2 (same address on all EVM chains)218- Proxy admin same address on all chains via CREATE2219- Deployment scripts idempotent (check if already deployed)220- Cross-chain governance for upgrade coordination221- L1 as source of truth, L2 as execution layer222223### Gas Budget Guidelines (EVM)224- Simple transfer: 21,000 gas225- ERC-20 transfer: ~50,000 gas226- ERC-721 mint: ~100,000 gas227- Uniswap swap: ~150,000 gas228- Complex AMM operation: ~300,000 gas229- L1 block gas limit: 30M (Ethereum)230- L2 block gas limit: 30M-1B (depends on L2)231232## Rules2331. Use Solidity for EVM chains (Ethereum, Polygon, Arbitrum, Optimism, Base, BSC)2342. Use Rust for Solana (Anchor framework as default), NEAR, and Polkadot ink!2353. Use Haskell/Plutus for Cardano smart contracts2364. Always follow checks-effects-interactions pattern regardless of language2375. Use Foundry (forge) for Solidity development and testing as default toolchain2386. Include gas optimization in every code review — storage is expensive, calldata is cheaper2397. Never hardcode sensitive parameters — use constructor args, setters with timelock2408. Default to UUPS for upgradeable contracts over transparent proxy2419. Use OpenZeppelin audited libraries over custom implementations24210. Always use explicit visibility (public, external, internal, private)24311. Avoid tx.origin for authentication — use msg.sender24412. Validate all external inputs with require or custom errors24513. Emit events for all state-changing operations24614. Test on testnet with real conditions before mainnet24715. Transfer ownership to multi-sig or timelock, not EOA248249## References250 - references/blockchain-application-advanced.md — Blockchain Application Advanced Topics251 - references/blockchain-application-fundamentals.md — Blockchain Application Fundamentals252 - references/cairo-language.md — Cairo Language (StarkNet)253 - references/contract-security.md — Smart Contract Security254 - references/haskell-plutus.md — Haskell & Plutus (Cardano)255 - references/move-language.md — Move Language (Sui & Aptos)256 - references/rust-smart-contracts.md — Rust Smart Contracts257 - references/smart-contract-patterns.md — Smart Contract Design Patterns258 - references/solidity-evm.md — Solidity & EVM Deep Dive259 - references/vyper-language.md — Vyper Language260 - references/cross-chain-deployment.md — Cross-Chain Deployment Strategy261 - references/gas-optimization-patterns.md — Gas Optimization Techniques262263## Phase264blockchain → blockchain-application265266## Handoff267blockchain-application → blockchain-testing (for test strategy implementation)268blockchain-application → blockchain-security (for pre-audit review)269270---271> Source: [j4flmao/agent-skills](https://github.com/j4flmao/agent-skills) — distributed by [TomeVault](https://tomevault.io).272<!-- tomevault:4.0:skill_md:2026-06-15 -->