/foundry-counter

Just working through some basic workflows.

Primary LanguageSolidity

Foundry Counter Example

Just a simple project for me to practice the basic workflows of Foundry development.

Manual Testing with Anvil

  1. Start an Anvil instance (on another terminal) by running anvil. You should get a bunch of public keys and private keys as well as the text "Listening on 127.0.0.1:8545".

  2. Make a .env file at project root and place one of Anvil's provided private keys (e.g.PRIVATE_KEY=0x1234...).

  3. Run the following to deploy:

    forge script script/Counter.s.sol --broadcast --rpc-url http://localhost:8545
  4. (optional) Check that the contract is there by doing a cast call:

    cast call <contract_deployed_address> "number()(uint256)" --rpc-url http://localhost:8545
  5. (optional) Send a transaction to the contract by doing a cast send:

    cast send <contract_deployed_address> "increment()" --rpc-url http://localhost:8545 --private-key <private_key_from_anvil>

Usage

Build

$ forge build

Test

$ forge test

Format

$ forge fmt

Gas Snapshots

$ forge snapshot

Anvil

$ anvil

Deploy

$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>

Cast

$ cast <subcommand>

Help

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