Skip to content

Commit

Permalink
foundry: separate out your contract deployments (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 authored Aug 1, 2024
1 parent e1b39d0 commit 8e0dd0c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
21 changes: 21 additions & 0 deletions packages/foundry/script/00_deploy_your_contract.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "./DeployHelpers.s.sol";

contract DeployYourContract is ScaffoldETHDeploy {
function run() external {
uint256 deployerPrivateKey = setupLocalhostEnv();
vm.startBroadcast(deployerPrivateKey);

YourContract yourContract = new YourContract(vm.addr(deployerPrivateKey));
console.logString(
string.concat(
"YourContract deployed at: ", vm.toString(address(yourContract))
)
);

vm.stopBroadcast();
}
}
38 changes: 18 additions & 20 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,33 @@ pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "./DeployHelpers.s.sol";
import { DeployYourContract } from "./00_deploy_your_contract.s.sol";

contract DeployScript is ScaffoldETHDeploy {
uint256 deployerPrivateKey;

error InvalidPrivateKey(string);

function run() external {
uint256 deployerPrivateKey = setupLocalhostEnv();
constructor() {
deployerPrivateKey = setupLocalhostEnv();
}

function run() external ScaffoldEthDeployerRunner {
DeployYourContract deployYourContract = new DeployYourContract();
deployYourContract.run();

// deploy more contracts here
// DeployMyContract deployMyContract = new DeployMyContract();
// deployMyContract.run();
}

modifier ScaffoldEthDeployerRunner() {
if (deployerPrivateKey == 0) {
revert InvalidPrivateKey(
"You don't have a deployer account. Make sure you have set DEPLOYER_PRIVATE_KEY in .env or use `yarn generate` to generate a new random account"
);
}
vm.startBroadcast(deployerPrivateKey);

YourContract yourContract = new YourContract(vm.addr(deployerPrivateKey));
console.logString(
string.concat(
"YourContract deployed at: ", vm.toString(address(yourContract))
)
);

vm.stopBroadcast();

/**
* This function generates the file containing the contracts Abi definitions.
* These definitions are used to derive the types needed in the custom scaffold-eth hooks, for example.
* This function should be called last.
*/
_;
exportDeployments();
}

function test() public { }
}

0 comments on commit 8e0dd0c

Please sign in to comment.