From d9208373a18bf52aaecf8d19dce980d6580da301 Mon Sep 17 00:00:00 2001 From: Paul Razvan Berg Date: Sun, 5 Feb 2023 14:07:12 +0200 Subject: [PATCH] refactor: use mnemonic in deployment script docs: document BIP39 mnmemonic in README --- README.md | 3 +++ script/DeployFoo.s.sol | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2333049..6024b23 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/script/DeployFoo.s.sol b/script/DeployFoo.s.sol index b26f1f4..92d6ec4 100644 --- a/script/DeployFoo.s.sol +++ b/script/DeployFoo.s.sol @@ -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(); }