Skip to content

Commit 034cf26

Browse files
committed
Extra scripts
1 parent d6178af commit 034cf26

File tree

14 files changed

+264
-6
lines changed

14 files changed

+264
-6
lines changed

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
2+
13
# RPC URLs
24
ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/Yf0ffpkJ7iHBv3ztyroy1j
35
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/f0ffpkJ7iHBv3ztyroy1j
46

57
# Private key for deployment (use a test key!)
68
PRIVATE_KEY=1f625dc57eb350e7f89ce150dd40f448f3fa2bf1a5e58473393a7561c16a65a1
9+
SEPOLIA_PRIVATE_KEY=1f625dc57eb350e7f89ce150dd40f448f3fa2bf1a5e58473393a7561c16a65a1
10+
LOCAL_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # Anvil's default key
711

812
# Etherscan API key for verification
913
ETHERSCAN_API_KEY=your_etherscan_api_key
14+
15+
# Contract addresses (will be populated after deployment)
16+
MAINNET_CONTRACT_ADDRESS=
17+
SEPOLIA_CONTRACT_ADDRESS=
18+
LOCAL_CONTRACT_ADDRESS=

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
26+
# Foundry
27+
contracts/cache/
28+
contracts/out/
29+
contracts/broadcast/
30+
31+
# Foundry lib
32+
lib/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "lib/forge-std"]
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/openzeppelin-contracts"]
5+
path = lib/openzeppelin-contracts
6+
url = https://github.com/OpenZeppelin/openzeppelin-contracts

contracts/deploy-config.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"1": {
3+
"name": "mainnet",
4+
"contracts": {
5+
"MyContract": ""
6+
}
7+
},
8+
"11155111": {
9+
"name": "sepolia",
10+
"contracts": {
11+
"MyContract": ""
12+
}
13+
},
14+
"31337": {
15+
"name": "localhost",
16+
"contracts": {
17+
"MyContract": ""
18+
}
19+
}
20+
}

contracts/script/Deploy.s.sol

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "../../lib/forge-std/src/Script.sol";
5+
import "../src/MyContract.sol";
6+
7+
contract DeployScript is Script {
8+
function run() external returns (MyContract) {
9+
uint256 deployerPrivateKey;
10+
11+
// Determine which private key to use based on chain ID
12+
if (block.chainid == 1) {
13+
// Mainnet
14+
deployerPrivateKey = vm.envUint("PRIVATE_KEY");
15+
} else if (block.chainid == 11155111) {
16+
// Sepolia
17+
deployerPrivateKey = vm.envUint("SEPOLIA_PRIVATE_KEY");
18+
} else {
19+
// Local (Anvil/Hardhat)
20+
deployerPrivateKey = vm.envUint("LOCAL_PRIVATE_KEY");
21+
}
22+
23+
vm.startBroadcast(deployerPrivateKey);
24+
25+
MyContract myContract = new MyContract();
26+
27+
console.log("MyContract deployed to:", address(myContract));
28+
console.log("Network:", block.chainid);
29+
30+
vm.stopBroadcast();
31+
32+
return myContract;
33+
}
34+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "forge-std/Script.sol";
5+
6+
contract HelperConfig is Script {
7+
struct NetworkConfig {
8+
uint256 deployerKey;
9+
address someOtherContract; // If you need to interact with existing contracts
10+
}
11+
12+
NetworkConfig public activeNetworkConfig;
13+
14+
constructor() {
15+
if (block.chainid == 11155111) {
16+
activeNetworkConfig = getSepoliaConfig();
17+
} else if (block.chainid == 1) {
18+
activeNetworkConfig = getMainnetConfig();
19+
} else {
20+
activeNetworkConfig = getAnvilConfig();
21+
}
22+
}
23+
24+
function getSepoliaConfig() public view returns (NetworkConfig memory) {
25+
return NetworkConfig({
26+
deployerKey: vm.envUint("SEPOLIA_PRIVATE_KEY"),
27+
someOtherContract: address(0) // Add actual addresses if needed
28+
});
29+
}
30+
31+
function getMainnetConfig() public view returns (NetworkConfig memory) {
32+
return NetworkConfig({
33+
deployerKey: vm.envUint("PRIVATE_KEY"),
34+
someOtherContract: address(0)
35+
});
36+
}
37+
38+
function getAnvilConfig() public returns (NetworkConfig memory) {
39+
// Deploy mocks if needed for local testing
40+
return NetworkConfig({
41+
deployerKey: vm.envUint("LOCAL_PRIVATE_KEY"),
42+
someOtherContract: address(0)
43+
});
44+
}
45+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "forge-std/Script.sol";
5+
6+
contract SaveDeployment is Script {
7+
function saveContract(string memory name, address addr) external {
8+
string memory chainId = vm.toString(block.chainid);
9+
string memory json = "deployments";
10+
11+
vm.serializeAddress(json, name, addr);
12+
13+
string memory filename = string.concat(
14+
"./deployments/",
15+
chainId,
16+
".json"
17+
);
18+
19+
vm.writeJson(vm.serializeString(json, "chainId", chainId), filename);
20+
}
21+
}

contracts/src/MyContract.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
contract MyContract {
5+
uint256 public value;
6+
7+
event ValueChanged(uint256 newValue);
8+
9+
function setValue(uint256 _value) public {
10+
value = _value;
11+
emit ValueChanged(_value);
12+
}
13+
}

contracts/test/MyContract.t.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "forge-std/Test.sol";
5+
import "../src/MyContract.sol";
6+
7+
contract MyContractTest is Test {
8+
MyContract public myContract;
9+
10+
function setUp() public {
11+
myContract = new MyContract();
12+
}
13+
14+
function testSetValue() public {
15+
myContract.setValue(42);
16+
assertEq(myContract.value(), 42);
17+
}
18+
}

foundry.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,26 @@ broadcast = "contracts/broadcast"
1111
optimizer = true
1212
optimizer_runs = 200
1313

14-
# Network settings
15-
eth_rpc_url = "${ETH_RPC_URL}"
14+
1615

1716
# Specify remappings if needed
1817
remappings = [
1918
"@openzeppelin/=lib/openzeppelin-contracts/",
20-
]
19+
]
20+
21+
# Sepolia configuration
22+
[profile.sepolia]
23+
eth_rpc_url = "${SEPOLIA_RPC_URL}"
24+
25+
# Mainnet configuration
26+
[profile.mainnet]
27+
eth_rpc_url = "${MAINNET_RPC_URL}"
28+
29+
# Local configuration
30+
[profile.local]
31+
eth_rpc_url = "http://localhost:8545"
32+
33+
# Etherscan configuration
34+
[etherscan]
35+
mainnet = { key = "${ETHERSCAN_API_KEY}" }
36+
sepolia = { key = "${ETHERSCAN_API_KEY}" }

0 commit comments

Comments
 (0)