refactor: use mnemonic in deployment script

docs: document BIP39 mnmemonic in README
This commit is contained in:
Paul Razvan Berg 2023-02-05 14:07:12 +02:00
parent e0967de8c5
commit d9208373a1
No known key found for this signature in database
GPG Key ID: BCC366159BD63828
2 changed files with 10 additions and 1 deletions

View File

@ -142,6 +142,9 @@ Deploy to Anvil:
$ forge script script/DeployFoo.s.sol --broadcast --fork-url http://localhost:8545
```
For this script to work, you need to have a `MNEMONIC` environment variable set to a valid
[BIP39 mnemonic](https://iancoleman.io/bip39/).
For instructions on how to deploy to a testnet or mainnet, check out the
[Solidity Scripting tutorial](https://book.getfoundry.sh/tutorials/solidity-scripting.html).

View File

@ -6,10 +6,16 @@ import { Foo } from "../src/Foo.sol";
/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract DeployFoo is Script {
address internal deployer;
Foo internal foo;
function setUp() public virtual {
string memory mnemonic = vm.envString("MNEMONIC");
(deployer,) = deriveRememberKey(mnemonic, 0);
}
function run() public {
vm.startBroadcast();
vm.startBroadcast(deployer);
foo = new Foo();
vm.stopBroadcast();
}