From c4d8b72141a97acf7cc322fae606756230989fcf Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Fri, 12 Jan 2024 01:35:37 -0500 Subject: [PATCH 1/9] add a guide for using the create2 strategy --- .../ignition/docs/guides/_dirinfo.yaml | 1 + .../content/ignition/docs/guides/create2.md | 138 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 docs/src/content/ignition/docs/guides/create2.md diff --git a/docs/src/content/ignition/docs/guides/_dirinfo.yaml b/docs/src/content/ignition/docs/guides/_dirinfo.yaml index 18ba9ad6f5..7d824da1c8 100644 --- a/docs/src/content/ignition/docs/guides/_dirinfo.yaml +++ b/docs/src/content/ignition/docs/guides/_dirinfo.yaml @@ -9,3 +9,4 @@ order: - /tests - /verify - /viem + - /create2 diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md new file mode 100644 index 0000000000..f0a1fe2160 --- /dev/null +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -0,0 +1,138 @@ +# Deploying Via Create2 + +When deploying contracts, you may want to deploy them to a specific address. This can be useful for a variety of reasons, such as deploying a contract to the same address on multiple networks. Hardhat Ignition makes this easy by allowing you to deploy your existing Ignition modules via a `create2` deployment utilizing the [CreateX factory](https://createx.rocks/). + +::: tip + +As is the case when using any unaudited contract system, please be aware of the [security considerations](https://github.com/pcaversaccio/createx?tab=readme-ov-file#security-considerations) of using the CreateX factory on a mainnet network. + +::: + +## Deploying on the Sepolia testnet + +We are going to use the [Sepolia testnet](https://ethereum.org/en/developers/docs/networks/#sepolia) to deploy our Ignition module, so you need to add this network in your Hardhat config. Here we are using [Alchemy](https://alchemy.com/) to connect to the network. + +:::tip + +For more information on `vars` and configuration variables, please see our [configuration variables guide](../../../hardhat-runner/docs/guides/configuration-variables.md). + +::: + +::::tabsgroup{options=TypeScript,JavaScript} + +:::tab{value=TypeScript} + +```ts +// Go to https://alchemy.com, sign up, create a new App in +// its dashboard, and set the Hardhat configuration variable +// ALCHEMY_API_KEY to the key +const ALCHEMY_API_KEY = vars.get("ALCHEMY_API_KEY"); + +// Replace this private key with your Sepolia test account private key +// To export your private key from Coinbase Wallet, go to +// Settings > Developer Settings > Show private key +// To export your private key from Metamask, open Metamask and +// go to Account Details > Export Private Key +// Beware: NEVER put real Ether into testing accounts +const SEPOLIA_PRIVATE_KEY = vars.get("SEPOLIA_PRIVATE_KEY"); + +export default { + // ...rest of your config... + networks: { + sepolia: { + url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`, + accounts: [SEPOLIA_PRIVATE_KEY], + }, + }, +}; +``` + +::: + +:::tab{value=JavaScript} + +```js +// Go to https://alchemy.com, sign up, create a new App in +// its dashboard, and set the Hardhat configuration variable +// ALCHEMY_API_KEY to the key +const ALCHEMY_API_KEY = vars.get("ALCHEMY_API_KEY"); + +// Replace this private key with your Sepolia test account private key +// To export your private key from Coinbase Wallet, go to +// Settings > Developer Settings > Show private key +// To export your private key from Metamask, open Metamask and +// go to Account Details > Export Private Key +// Beware: NEVER put real Ether into testing accounts +const SEPOLIA_PRIVATE_KEY = vars.get("SEPOLIA_PRIVATE_KEY"); + +module.exports = { + // ...rest of your config... + networks: { + sepolia: { + url: `https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`, + accounts: [SEPOLIA_PRIVATE_KEY], + }, + }, +}; +``` + +::: + +:::: + +To deploy on Sepolia you need to send some Sepolia ether to the address that's going to be making the deployment. You can get testnet ether from a faucet, a service that distributes testing-ETH for free. Here is one for Sepolia: + +- [Alchemy Sepolia Faucet](https://sepoliafaucet.com/) + +:::tip + +This guide assumes you are using the contracts and Ignition module from the [quick start guide](/ignition/docs/getting-started#quick-start), but the steps are the same for any deployment. + +::: + +You can now run the deployment with `create2` using the newly added Sepolia network: + +::::tabsgroup{options="TypeScript,JavaScript"} + +:::tab{value="TypeScript"} + +```sh +npx hardhat ignition deploy ignition/modules/Apollo.ts --network sepolia --strategy create2 +``` + +::: + +:::tab{value="JavaScript"} + +```sh +npx hardhat ignition deploy ignition/modules/Apollo.js --network sepolia --strategy create2 +``` + +::: + +:::: + +The `--strategy create2` flag tells Ignition to deploy the module using `create2`. You should see output similar to the following: + +```sh +Compiled 1 Solidity file successfully (evm target: paris). +Hardhat Ignition 🚀 + +Deploying [ Apollo ] with strategy < create2 > + +Batch #1 + Executed Apollo#Rocket + +Batch #2 + Executed Apollo#Rocket.launch + +[ Apollo ] successfully deployed 🚀 + +Deployed Addresses + +Apollo#Rocket - 0x8A818FCD6dcdFCF59A1aeebB241644f256Bd19c3 +``` + +Deploying this module using the `create2` strategy will deploy the contract to this same address, regardless of what network you're deploying to. + +To read more about `create2` and the CreateX factory, please see the [CreateX documentation](https://github.com/pcaversaccio/createx). From aa6a8f3b4850aee836cb1c967e75dc529dc9b2bf Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Sat, 17 Feb 2024 01:36:39 -0500 Subject: [PATCH 2/9] update create2 guide for salt config --- .../content/ignition/docs/guides/create2.md | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index f0a1fe2160..9df052aa2c 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -90,6 +90,52 @@ This guide assumes you are using the contracts and Ignition module from the [qui ::: +Our last step before deploying is to add a custom salt for the deployment. This step is optional, but it's recommended to avoid any potential collisions with other deployments. You can add a custom salt via your Hardhat config: + +::::tabsgroup{options=TypeScript,JavaScript} + +:::tab{value=TypeScript} + +```ts +export default { + // ...rest of your config... + ignition: { + strategyConfig: { + create2: { + salt: "custom-salt", + }, + }, + }, +}; +``` + +::: + +:::tab{value=JavaScript} + +```js +module.exports = { + // ...rest of your config... + ignition: { + strategyConfig: { + create2: { + salt: "custom-salt", + }, + }, + }, +}; +``` + +::: + +:::: + +:::tip + +To learn more about salts and how they work, as well as additional security considerations, please see the [CreateX documentation](https://github.com/pcaversaccio/createx?tab=readme-ov-file#permissioned-deploy-protection-and-cross-chain-redeploy-protection). + +::: + You can now run the deployment with `create2` using the newly added Sepolia network: ::::tabsgroup{options="TypeScript,JavaScript"} From 2a4369b6b26919d31b2912c5f071cf6c6c713af4 Mon Sep 17 00:00:00 2001 From: John Kane Date: Tue, 5 Mar 2024 11:37:50 +0000 Subject: [PATCH 3/9] docs: tweak capitalisation of title --- docs/src/content/ignition/docs/guides/create2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index 9df052aa2c..d41b038fc2 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -1,4 +1,4 @@ -# Deploying Via Create2 +# Deploying via Create2 When deploying contracts, you may want to deploy them to a specific address. This can be useful for a variety of reasons, such as deploying a contract to the same address on multiple networks. Hardhat Ignition makes this easy by allowing you to deploy your existing Ignition modules via a `create2` deployment utilizing the [CreateX factory](https://createx.rocks/). From 0a3bd450c1798743f4b0ffa97ebb6523883fa048 Mon Sep 17 00:00:00 2001 From: John Kane Date: Tue, 5 Mar 2024 11:40:08 +0000 Subject: [PATCH 4/9] docs: fix to tip spacing --- docs/src/content/ignition/docs/guides/create2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index d41b038fc2..8fa1f2499a 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -2,7 +2,7 @@ When deploying contracts, you may want to deploy them to a specific address. This can be useful for a variety of reasons, such as deploying a contract to the same address on multiple networks. Hardhat Ignition makes this easy by allowing you to deploy your existing Ignition modules via a `create2` deployment utilizing the [CreateX factory](https://createx.rocks/). -::: tip +:::tip As is the case when using any unaudited contract system, please be aware of the [security considerations](https://github.com/pcaversaccio/createx?tab=readme-ov-file#security-considerations) of using the CreateX factory on a mainnet network. From 98080fb51f6be02c3946048120110ba03da55bfe Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Thu, 7 Mar 2024 01:53:42 -0500 Subject: [PATCH 5/9] minor fixes --- docs/src/content/ignition/docs/guides/create2.md | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index 8fa1f2499a..1f00594fa9 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -1,6 +1,6 @@ # Deploying via Create2 -When deploying contracts, you may want to deploy them to a specific address. This can be useful for a variety of reasons, such as deploying a contract to the same address on multiple networks. Hardhat Ignition makes this easy by allowing you to deploy your existing Ignition modules via a `create2` deployment utilizing the [CreateX factory](https://createx.rocks/). +When deploying contracts, you may want to deploy them to a deterministic address. This can be useful for a variety of reasons, such as deploying a contract to the same address on multiple networks. Hardhat Ignition makes this easy by allowing you to deploy your existing Ignition modules via a `create2` deployment utilizing the [CreateX factory](https://createx.rocks/). :::tip @@ -12,12 +12,6 @@ As is the case when using any unaudited contract system, please be aware of the We are going to use the [Sepolia testnet](https://ethereum.org/en/developers/docs/networks/#sepolia) to deploy our Ignition module, so you need to add this network in your Hardhat config. Here we are using [Alchemy](https://alchemy.com/) to connect to the network. -:::tip - -For more information on `vars` and configuration variables, please see our [configuration variables guide](../../../hardhat-runner/docs/guides/configuration-variables.md). - -::: - ::::tabsgroup{options=TypeScript,JavaScript} :::tab{value=TypeScript} @@ -130,12 +124,6 @@ module.exports = { :::: -:::tip - -To learn more about salts and how they work, as well as additional security considerations, please see the [CreateX documentation](https://github.com/pcaversaccio/createx?tab=readme-ov-file#permissioned-deploy-protection-and-cross-chain-redeploy-protection). - -::: - You can now run the deployment with `create2` using the newly added Sepolia network: ::::tabsgroup{options="TypeScript,JavaScript"} @@ -164,7 +152,7 @@ The `--strategy create2` flag tells Ignition to deploy the module using `create2 Compiled 1 Solidity file successfully (evm target: paris). Hardhat Ignition 🚀 -Deploying [ Apollo ] with strategy < create2 > +Deploying [ Apollo ] with strategy < create2 > Batch #1 Executed Apollo#Rocket From 699304cadcbab8e1a73a296050f8b223fe866a1b Mon Sep 17 00:00:00 2001 From: John Kane Date: Thu, 7 Mar 2024 18:21:18 +0000 Subject: [PATCH 6/9] docs(create2): the salt is required Update the text to indicate that the salt is required. Also set a valid but obviously example salt. --- docs/src/content/ignition/docs/guides/create2.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index 1f00594fa9..391c0c134f 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -84,7 +84,7 @@ This guide assumes you are using the contracts and Ignition module from the [qui ::: -Our last step before deploying is to add a custom salt for the deployment. This step is optional, but it's recommended to avoid any potential collisions with other deployments. You can add a custom salt via your Hardhat config: +Our last step before deploying is to add a salt for the deployment. This step is required to avoid any potential collisions with other deployments. The salt must be a 32 byte hex encoded string. You can add the salt via your Hardhat config: ::::tabsgroup{options=TypeScript,JavaScript} @@ -96,7 +96,7 @@ export default { ignition: { strategyConfig: { create2: { - salt: "custom-salt", + salt: "0x0000000000000000000000000000000000000000000000000000000000000000", }, }, }, @@ -113,7 +113,7 @@ module.exports = { ignition: { strategyConfig: { create2: { - salt: "custom-salt", + salt: "0x0000000000000000000000000000000000000000000000000000000000000000", }, }, }, From b0d32c23816a732208c699b82e07afad1fce5fc5 Mon Sep 17 00:00:00 2001 From: John Kane Date: Thu, 7 Mar 2024 19:11:15 +0000 Subject: [PATCH 7/9] docs(create2): remove brackets --- docs/src/content/ignition/docs/guides/create2.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index 391c0c134f..232f2d68a3 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -96,6 +96,7 @@ export default { ignition: { strategyConfig: { create2: { + // To learn more about salts, see the CreateX documentation salt: "0x0000000000000000000000000000000000000000000000000000000000000000", }, }, @@ -113,6 +114,7 @@ module.exports = { ignition: { strategyConfig: { create2: { + // To learn more about salts, see the CreateX documentation salt: "0x0000000000000000000000000000000000000000000000000000000000000000", }, }, @@ -152,7 +154,7 @@ The `--strategy create2` flag tells Ignition to deploy the module using `create2 Compiled 1 Solidity file successfully (evm target: paris). Hardhat Ignition 🚀 -Deploying [ Apollo ] with strategy < create2 > +Deploying [ Apollo ] with strategy create2 Batch #1 Executed Apollo#Rocket From 12b1da1d2295afd699f2ab7b2a812e7d0e1f9f46 Mon Sep 17 00:00:00 2001 From: John Kane Date: Thu, 7 Mar 2024 23:00:35 +0000 Subject: [PATCH 8/9] docs(create2): update deployed address to match salt --- docs/src/content/ignition/docs/guides/create2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index 232f2d68a3..7885bd5d64 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -166,7 +166,7 @@ Batch #2 Deployed Addresses -Apollo#Rocket - 0x8A818FCD6dcdFCF59A1aeebB241644f256Bd19c3 +Apollo#Rocket - 0xD19BF213aD9D2026cA2bb52AFD3E4C1f597E4990 ``` Deploying this module using the `create2` strategy will deploy the contract to this same address, regardless of what network you're deploying to. From f1b4f2cb1a6c057f88acd24e1d25f33d9a23a36a Mon Sep 17 00:00:00 2001 From: John Kane Date: Mon, 11 Mar 2024 12:04:42 +0000 Subject: [PATCH 9/9] Update docs/src/content/ignition/docs/guides/create2.md --- docs/src/content/ignition/docs/guides/create2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/ignition/docs/guides/create2.md b/docs/src/content/ignition/docs/guides/create2.md index 7885bd5d64..7844b9bc43 100644 --- a/docs/src/content/ignition/docs/guides/create2.md +++ b/docs/src/content/ignition/docs/guides/create2.md @@ -166,7 +166,7 @@ Batch #2 Deployed Addresses -Apollo#Rocket - 0xD19BF213aD9D2026cA2bb52AFD3E4C1f597E4990 +Apollo#Rocket - 0x10D3deBd2F40F8EaB28a1d3b472a1269a12E9855 ``` Deploying this module using the `create2` strategy will deploy the contract to this same address, regardless of what network you're deploying to.