Simulation ->
forge script script/DeployContract.sol --rpc-url <ANVIL CHAIN URL>
Actual deployment on local chain ->
forge script script/DeployContract.sol --rpc-url <LOCAL CHAIN URL> --broadcast <PRIVATE KEY from ANVIL CHAIN>
To import a library from GitHub, we need to run the following command:
forge install <OWNER-NAME>/<REPO-NAME>@<VERSION> --no-commit
# For example
forge install smartcontractkit/chainlink-brownie-contracts@1.1.1 --no-commitRun cast wallet import -i <name> or cast wallet import <name> --interactive.
Paste the private key into the prompt.
Set a strong password at least 20 chars long so that it can't be brute-forced.
Use the account and sender flag when running Foundry commands like this: forge script <script_location>:<contract_name> --rpc-url <rpc_url> --account <name> --sender <public_key> --broadcast.
If actually deploying to, for example, Sepolia, we would also add --verify --etherscan-api-key.
Type cast wallet list to check the list of wallets.
(Can also go to home directory, then cd ./foundry/keystores/, then ls to see list of keystores.)
Then type cast <wallet_name> to see the encrypted version of the private key which follows ERC-2335.
Run cast send <Contract_Address> "<fn. sign>" args --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> to send values to a function as parameters. Sending transaction.
cast call has the same arguments as above but it is used for calling a function where a value is returned. Calling transaction.
cast --to-base <HEX_VALUE> dec to convert hex values to decimal values.
foundry-zksync installed.
To switch back to vanilla Foundry, simply run foundryup, and to switch back to foundry-zksync, run foundryup-zksync
Run forge build --zksync to compile with zkSync
-
--match-testfor specifying a test function.-mis deprecated--match-pathfor specifying the path of the test contract--fork-urlfor forking any network--gas-reportfor gas report--debugfor inline opcode debugger- Super helpful for looking at the stack and/or memory
-
- Creates a file (
.gas-snapshot) with the gas costs of the test - Use with same commands as for
forge test
- Creates a file (
-
- To format your code
-
<CONTRACT NAME> storageLayoutshows the storage of the contractconstantandimmutableglobal variables do not show up in storage
-
--report debuggives the details of all tests and the lines that aren't covered by the tests. Adding> <FILE_NAME>.txtto it would store the output in a txt file in the directory
vm.expectRevert(...)is used when the next LoC is supposed to revert. If not, the test failsvm.prank(address)sets the provided address as the msg.sender for the next callmakeAddr(string)takes a name as a string and generates an address for the same namevm.deal(address, uint256)takes an address and gives it an amount of tokenshoax(address, uint256)combination ofvm.prank()andvm.deal()vm.txGasPrice(uint256)sets the tx.gasprice() for the rest of the transactionvm.warp(uint256)alters block.timestampvm.expectEmit(bool,bool,bool,bool, address)checks if an event was emitted. The first three bool values are for indexed values emitted with events, and the fourth one is for any non-indexed values present in the events. The address is of the contractvm.roll(uint256)alters block.numbervm.recordLogs()records all the emitted eventsvm.getRecordedLogs()gets all the recorded logs in an array of Log objects, defined inforge-std/Vm.sol
-
./src/DevOpsTools.sol- Can be used to get the most recent deployment of your contract. Need to setffi = trueinfoundry.tomlso that foundry can run bash scripts on your device, preferred to keep it asfalsein general
- Gas costs can be calculated by taking gas used in testnet, multiply by latest gas price on mainnet and convert to USD. Visible that Eth mainnet is very expensive so prefer to deploy on an L2 chain like zkSync.
- forge -> Compiling and interacting with contracts
- cast -> Interacting with contracts that have already been deployed
- anvil -> To deploy a local blockchain
- chisel -> To type and run small snippets of solidity in terminal, maybe for checking something or testing
addresscannot be explicitly cast asuint256. It needs to be cast asuint160and then asuint256.address a = msg.sender; return uint256(uint160(a));
- When deploying with anvil and using it, the gas price defaults to 0.