Foundryの学習帳
Published:
Foundryとは?
Foundryは、Ethereumアプリケーション開発のためのポータブルでモジュール型のツールキットです。Rustで書かれており、高速で効率的なスマートコントラクト開発環境を提供します。
主な特徴
- 高速なテスト実行
- Rustで実装されているため、非常に高速なテスト実行が可能
- Solidityで直接テストを書ける(JavaScript/TypeScript不要)
- 主要なツール
- Forge: スマートコントラクトのビルド、テスト、デプロイを行うツール
- Cast: EVMチェーンと対話するためのCLIツール
- Anvil: ローカルEthereumノード(Hardhat NetworkやGanacheに相当)
- Chisel: Solidity REPL(対話型シェル)。Solidityコードを対話的に実行・テストできる
- 開発体験
- シンプルで直感的なコマンドラインインターフェース
- 依存関係管理が簡単
- 強力なデバッグ機能
- Solidityネイティブ
- Solidityで直接テストを記述可能
- Solidityの最新機能をサポート
他のツールとの比較
- Hardhat: JavaScript/TypeScriptベース、豊富なプラグイン
- Foundry: Rustベース、高速なテスト実行、Solidityネイティブ
Foundryは、特にテストの実行速度とSolidityネイティブな開発体験を重視する開発者に人気があります。
Foundryのインストール
┌──(stardust✨stardust)-[~]
└─$ curl -L https://foundry.paradigm.xyz | bash
┌──(stardust✨stardust)-[~]
└─$ exec $SHELL -l
┌──(stardust✨stardust)-[~]
└─$ foundryup
.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
╔═╗ ╔═╗ ╦ ╦ ╔╗╔ ╔╦╗ ╦═╗ ╦ ╦ Portable and modular toolkit
╠╣ ║ ║ ║ ║ ║║║ ║║ ╠╦╝ ╚╦╝ for Ethereum Application Development
╚ ╚═╝ ╚═╝ ╝╚╝ ═╩╝ ╩╚═ ╩ written in Rust.
.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
Repo : https://github.com/foundry-rs/foundry
Book : https://book.getfoundry.sh/
Chat : https://t.me/foundry_rs/
Support : https://t.me/foundry_support/
Contribute : https://github.com/foundry-rs/foundry/blob/HEAD/CONTRIBUTING.md
.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx
(snip)
┌──(stardust✨stardust)-[~]
└─$ forge --version
forge Version: 1.5.1-stable
Commit SHA: b0a9dd9ceda36f63e2326ce530c10e6916f4b8a2
Build Timestamp: 2025-12-22T11:39:01.425730780Z (1766403541)
Build Profile: maxperf
┌──(stardust✨stardust)-[~]
└─$ cast --version
cast Version: 1.5.1-stable
Commit SHA: b0a9dd9ceda36f63e2326ce530c10e6916f4b8a2
Build Timestamp: 2025-12-22T11:39:01.425730780Z (1766403541)
Build Profile: maxperf
┌──(stardust✨stardust)-[~]
└─$ anvil --version
anvil Version: 1.5.1-stable
Commit SHA: b0a9dd9ceda36f63e2326ce530c10e6916f4b8a2
Build Timestamp: 2025-12-22T11:39:01.425730780Z (1766403541)
Build Profile: maxperf
┌──(stardust✨stardust)-[~]
└─$ chisel --version
chisel Version: 1.5.1-stable
Commit SHA: b0a9dd9ceda36f63e2326ce530c10e6916f4b8a2
Build Timestamp: 2025-12-22T11:39:01.425730780Z (1766403541)
Build Profile: maxperf
Ethereium Sepolia上でFoundryを使って遊んでみる
自分の残高を取得する
FoundryのCastコマンドを使用して、Ethereum Sepoliaネットワーク上の残高を取得できます。
1. 基本的な残高取得コマンド
┌──(stardust✨stardust)-[~]
└─$ cast balance 0x53869B88306EB505f0fC66DaE482D42033F85253 --rpc-url https://eth-sepolia.g.alchemy.com/v2/8KbQVqn8tx_cRlE0fc-Rr -e
0.100000000000000000
ブログ更新コマンド
┌──(stardust✨stardust)-[~/stardustdotbox.github.io]
└─$ git add -A && git commit -m 'Foundryの学習帳' && git push
参考文献
- https://github.com/foundry-rs/foundry
- https://book.getfoundry.sh/
