Loading...
Loading...
Master Ethereum development including EVM, gas optimization, and client interactions
npx skill4agent add pluginagentmarketplace/custom-plugin-blockchain ethereum-developmentMaster Ethereum development including EVM internals, gas optimization, transaction mechanics, and client interactions.
# Invoke this skill for Ethereum development
Skill("ethereum-development", topic="gas", network="mainnet")// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Optimized {
// Pack into single slot (32 bytes)
struct User {
uint128 balance; // 16 bytes
uint64 lastUpdate; // 8 bytes
uint32 nonce; // 4 bytes
bool active; // 1 byte
// 3 bytes padding
}
mapping(address => User) public users;
}import { createPublicClient, http, keccak256, encodePacked, pad } from 'viem';
import { mainnet } from 'viem/chains';
const client = createPublicClient({ chain: mainnet, transport: http() });
// Read mapping value: balances[address]
async function getBalance(contract: `0x${string}`, user: `0x${string}`) {
const slot = keccak256(encodePacked(['address', 'uint256'], [user, 0n]));
return await client.getStorageAt({ address: contract, slot });
}import { createWalletClient, http, parseEther } from 'viem';
const client = createWalletClient({ transport: http() });
const hash = await client.sendTransaction({
to: '0x...',
value: parseEther('0.1'),
type: 'eip1559',
maxFeePerGas: parseGwei('30'),
maxPriorityFeePerGas: parseGwei('2'),
});| Technique | Savings | Example |
|---|---|---|
| Storage packing | ~20k/slot | |
| Calldata vs memory | ~3/byte | Use |
| Unchecked math | ~80/op | |
| Custom errors | ~200+ | |
| Short-circuit | Variable | Cheap checks first |
| Pitfall | Issue | Solution |
|---|---|---|
| Storage in loops | Expensive reads | Cache in memory first |
| String storage | Uses multiple slots | Use bytes32 when possible |
| Zero value storage | Full refund gone | Don't rely on SSTORE refunds |
# Check current gas prices
cast gas-price --rpc-url $RPC
cast basefee --rpc-url $RPCmaxFeePerGas# Trace transaction to find issue
cast run --trace $TX_HASH --rpc-url $RPC# Get current nonce
cast nonce $ADDRESS --rpc-url $RPC# Foundry essentials
forge build --sizes # Contract sizes
forge test --gas-report # Gas consumption
forge snapshot # Gas snapshots
cast storage $ADDR $SLOT # Read storage
cast call $ADDR "fn()" # Simulate callcontract GasTest is Test {
function test_GasOptimization() public {
uint256 gasBefore = gasleft();
target.optimizedFunction();
uint256 gasUsed = gasBefore - gasleft();
assertLt(gasUsed, 50000, "Too much gas used");
}
}02-ethereum-developmentsolidity-developmentweb3-frontend| Version | Date | Changes |
|---|---|---|
| 2.0.0 | 2025-01 | Production-grade with viem, gas optimization |
| 1.0.0 | 2024-12 | Initial release |