Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foundry: separate out your contract deployments #898

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
36 changes: 17 additions & 19 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 checkDeployerPrivateKey deploymentExporter {
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
DeployYourContract deployYourContract = new DeployYourContract();
deployYourContract.run();
}

modifier checkDeployerPrivateKey() {
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.
*/
modifier deploymentExporter() {
_;
exportDeployments();
}

function test() public { }
}