Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

taofei1001/Bank

Repository files navigation

Foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Documentation

https://book.getfoundry.sh/

Usage

Build

$ forge build

Test

$ forge test

Format

$ forge fmt

Gas Snapshots

$ forge snapshot

Anvil

$ anvil

Deploy

部署到 Sepolia 测试网

  1. 设置环境变量(推荐使用 .env 文件):

    # 创建 .env 文件
    echo "PRIVATE_KEY=your_private_key_here" > .env
    echo "SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/your_api_key" >> .env

    或者使用其他 RPC 提供商:

    • Alchemy: https://eth-sepolia.g.alchemy.com/v2/your_api_key
    • Infura: https://sepolia.infura.io/v3/your_api_key
    • 公共 RPC: https://rpc.sepolia.org
  2. 确保账户有足够的 Sepolia ETH:

  3. 部署 Bank 合约到 Sepolia:

    # 使用环境变量
    forge script script/Bank.s.sol:BankScript \
     --rpc-url $SEPOLIA_RPC_URL \
     --private-key $PRIVATE_KEY \
     --broadcast \
     --verify \
     --etherscan-api-key $ETHERSCAN_API_KEY

    或者直接指定参数:

    forge script script/Bank.s.sol:BankScript \
     --rpc-url https://sepolia.infura.io/v3/your_api_key \
     --private-key your_private_key \
     --broadcast
  4. 仅模拟部署(不实际部署):

    forge script script/Bank.s.sol:BankScript \
     --rpc-url $SEPOLIA_RPC_URL

部署参数说明

  • --rpc-url: Sepolia 测试网的 RPC 端点
  • --private-key: 部署账户的私钥(需要有足够的 Sepolia ETH)
  • --broadcast: 实际发送交易到网络
  • --verify: 在 Etherscan 上验证合约(需要 --etherscan-api-key)
  • --etherscan-api-key: Etherscan API 密钥(用于合约验证)

安全提示

⚠️ 重要:永远不要将包含真实私钥的 .env 文件提交到 Git! 确保 .env 文件已添加到 .gitignore 中。

Cast

$ cast <subcommand>

Help

$ forge --help
$ anvil --help
$ cast --help

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /