登链社区线上线下集训营参考代码库
$ forge build$ forge test$ forge fmt$ forge snapshot$ anvilforge create Counter --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 --broadcast
forge create Counter --account test_test --broadcast --rpc-url http://127.0.0.1:8545
forge create Counter --keystore .keys/wallet1 --rpc-url http://localhost:8545 --broadcast
forge script script/Counter.s.sol --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 --broadcast
$ forge script script/Counter_2.s.sol --rpc-url <your_rpc_url> --private-key <your_private_key>
forge script script/Counter.s.sol --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url http://localhost:8545 --broadcast
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
$ forge script script/xxx.sol --rpc-url local --broadcast
$ forge script script/TokenBank.s.sol --broadcast --rpc-url http://127.0.0.1:8545
# 在script 代码中加载账号
$ forge script script/MyERC20_2.s.sol --rpc-url http://localhost:8545 --broadcast
$ forge script script/MyERC20_2.s.sol --rpc-url sepolia --broadcast
forge verify-contract \
0xF02f3825618d0845Fdf65102A3C53A0aE2b75bb9 \
src/MyERC20.sol:MyERC20 \
--constructor-args $(cast abi-encode "constructor(string,string)" "OpenSpace Token" "OST") \
--verifier etherscan \
--verifier-url https://api-sepolia.etherscan.io/api \
--etherscan-api-key $ETHERSCAN_API_KEY \
--chain-id 11155111
forge verify-contract \
0xD3c6a2c8687cBCF63ac131E05c65Ee1BEa2e3241 \
src/Counter.sol:Counter \
--verifier etherscan \
--verifier-url $POLYSCAN_URL \
--etherscan-api-key $POLYSCAN_API_KEY \
--chain-id 137
forge inspect StorageVars storageLayout
forge inspect MyERC20 abi --json > MyERC20.json
$ cast <subcommand>
cast wallet -h # 查看所有的命令选项
cast wallet new [DIR] <ACCOUNT_NAME> # Create a new random keypair
cast wallet new-mnemonic # mnemonic phrase
cast wallet address [PRIVATE_KEY] # private key to an address
cast wallet import -i -k <KEYSTORE_DIR> <ACCOUNT_NAME>
cast wallet import --mnemonic "test test test test test test test test test test test junk” -k <KEYSTORE_DIR> <ACCOUNT_NAME>
cast to-wei 1 cast send 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 --value 1000000000000000000 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url local
cast send 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9
cast send 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 "transfer(address to, uint256 value)" 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 1000000000000000000000 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url local
cast send 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 "approve(address to, uint256 value)" 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 1000000000000000000000 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --rpc-url local
cast keccak 'transfer(address to, uint256 value)' 0xa9059c cast keccak 'transfer(address,uint256)' # 0xa9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b
cast sig 'transfer(address to, uint256 value)' cast sig 'transfer(address,uint256)'
//cast to-wei 1700 cast abi-encode "transfer(address to, uint256 value)" 0x28c6c06298d514db089934071355e5743bf21d60 1700000000
0x00000000000000000000000028c6c06298d514db089934071355e5743bf21d60000000000000000000000000000000000000000000000000000000006553f100
cast decode-calldata 'transfer(address to, uint256 value)' 0xa9059cbb00000000000000000000000028c6c06298d514db089934071355e5743bf21d60000000000000000000000000000000000000000000000000000000006553f100
cast pretty-calldata 0xa9059cbb00000000000000000000000028c6c06298d514db089934071355e5743bf21d60000000000000000000000000000000000000000000000000000000006553f100
cast abi-encode 'enc(uint a, bytes memory b)' 1 0x0123 #0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020123000000000000000000000000000000000000000000000000000000000000
cast sig-event 'Transfer(address indexed from, address indexed to, uint256 value)' 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
cast tx 0x5f7fd2457348472ec5c25500cae145b91843ccf3921e4cbe78fd91c39a8b6855 --rpc-url https://uk.rpc.blxrbdn.com cast receipt 0x5f7fd2457348472ec5c25500cae145b91843ccf3921e4cbe78fd91c39a8b6855 --rpc-url https://uk.rpc.blxrbdn.com
logs [{"address":"0xdac17f958d2ee523a2206206994597c13d831ec7","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000214095cca66b93f7dd819e51a19d6560f8450936","0x00000000000000000000000028c6c06298d514db089934071355e5743bf21d60"],"data":"0x000000000000000000000000000000000000000000000000000000006553f100","blockHash":"0x3bdf2afb4eddcb848093c6f2466804a45aea4c5b12532136e1f48a0e474a0719","blockNumber":"0x1570445","transactionHash":"0x5f7fd2457348472ec5c25500cae145b91843ccf3921e4cbe78fd91c39a8b6855","transactionIndex":"0x163","logIndex":"0x255","removed":false}]
forge test test/Cheatcode.t.sol --mt test_Roll -vv
forge test --mt test_Deal -vv
$ forge --help
$ anvil --help
$ cast --help0x0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000060 00000000000000000000000028c6c06298d514db089934071355e5743bf21d60 0000000000000000000000000000000000000000000000000000000000000002 0123000000000000000000000000000000000000000000000000000000000000
// 0x0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000080 00000000000000000000000028c6c06298d514db089934071355e5743bf21d60 00000000000000000000000000000000000000000000000000000000000000c0 0000000000000000000000000000000000000000000000000000000000000002 0123000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000002 7890000000000000000000000000000000000000000000000000000000000000