refer to:
https://book.getfoundry.sh/forge/deploying
特别简单。而且可以重复部署,没有hardhat 那种乱七八糟的概念。
forge create --rpc-url http://localhost:8545 --private-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d src/SayHi.sol:SayHi
随便创建一个 src/SayHi.sol 内容如下: (略)
太爽了。瞬间执行完。 使用hardhat 则需要10+s
[⠢] Compiling... No files changed, compilation skipped Deployer: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 Deployed to: 0x712516e61C8B383dF4A63CFe83d7701Bce54B03e Transaction hash: 0x9153f9916a55375fabb500e5265df6edaed0bc18d2f802034acae4bd7a1d40b4
调用目标函数:
假设我们需要部署一个constructor 有参数的contract:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; contract CallYular { address public owner; bool public flag; event callYularEvent(bool success, bytes data); constructor CallYular(address targetContract) { ... } }
forge create --rpc-url http://35.89.151.219:8000/a2bfcdfe-5ee5-4368-8c8e-bad8c517934a --private-key 0x79b4887c144c3915a2b1740e377420634d863d90642678106834c68c0e2f0cc4 --constructor-args "params1" "params2" --legacy src/CallYular.sol:CallYular
遇到错误: EIP-1559的问题:EIP-1559 not activated
命令后面加上 --legacy 即可。