
Foundry Base Usage
本文最后更新于 2024-04-22,本文发布时间距今超过 90 天, 文章内容可能已经过时。最新内容请以官方内容为准
Foundry Base Usage
- Create a .env (only for
Test Account
) - Input the private key of test account and RPC_URL
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 RPC_URL=http://127.0.0.1:8545
- Set the env variables by cmd
source ./.env
- Use the pre-setting variables by cmd
$RPC_URL
- Deploy the contracts and get the deployed address by cmd
- Deploy the contract without
--broadcast
will lead to dry-run
forge script [scriptPath] --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
- Deploy the contract without
- Call the funtions of contract
# Call the store function of contract and set the input param as 77 cast send [contractAddress] "store(uint256)" 77 --rpc-url $RPC_URL --private-key $PRIVATE_KEY # Call the retrieve function of contract and get the output value # Then pass it though pipe to cast to convert it to decimal cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 "retrieve()" | cast --to-dec
- Use the
--interactive
command to interact with the contract- If you don’t want to use the explicit
--rpc-url
and--private-key
command, you can use the--interactive
command to interact with the contract
- If you don’t want to use the explicit
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Unic
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果