| 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity ^0.8.19; |
| 3 | |
| 4 | import "forge-std/Script.sol"; |
| 5 | import "../src/Counter.sol"; |
| 6 | |
| 7 | contract DeployScript is Script { |
| 8 | function run() external { |
| 9 | uint256 deployerPrivateKey; |
| 10 | |
| 11 | // Use Anvil's first default account if no private key is provided |
| 12 | // Anvil account #0: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 |
| 13 | if (vm.envOr("PRIVATE_KEY", uint256(0)) == 0) { |
| 14 | deployerPrivateKey = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80; |
| 15 | console.log("Using Anvil default account"); |
| 16 | } else { |
| 17 | deployerPrivateKey = vm.envUint("PRIVATE_KEY"); |
| 18 | console.log("Using provided private key"); |
| 19 | } |
| 20 | |
| 21 | vm.startBroadcast(deployerPrivateKey); |
| 22 | |
| 23 | Counter counter = new Counter(); |
| 24 | |
| 25 | console.log("Counter deployed at:", address(counter)); |
| 26 | console.log("Deployed by:", vm.addr(deployerPrivateKey)); |
| 27 | |
| 28 | vm.stopBroadcast(); |
| 29 | } |
| 30 | } |