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

templatised foundry deploy script #43

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"networkName": "Anvil"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//SPDX-License-Identifier: MIT
import { withDefaults } from "../../../../../utils.js";

const content = ({ deploymentsScriptsImports, deploymentsLogic }) => `//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "./DeployHelpers.s.sol";
${deploymentsScriptsImports.filter(Boolean).join("\n")}

contract DeployScript is ScaffoldETHDeploy {
error InvalidPrivateKey(string);
Expand All @@ -11,19 +14,25 @@ contract DeployScript is ScaffoldETHDeploy {
uint256 deployerPrivateKey = setupLocalhostEnv();
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"
"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));

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

vm.stopBroadcast();

${deploymentsLogic.filter(Boolean).join("\n")}

/**
* 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.
Expand All @@ -33,4 +42,9 @@ contract DeployScript is ScaffoldETHDeploy {
}

function test() public {}
}
}`;

export default withDefaults(content, {
deploymentsScriptsImports: "",
deploymentsLogic: "",
});
Loading