
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
@kadena/hardhat-kadena-create2
Advanced tools
Hardhat plugin for deploying deterministic create2Factory contract
@kadena/hardhat-create2-proxy
is a Hardhat plugin that allows Ethereum developers to deploy their own create2Factory on chianweb evm.
This plugin uses @kadena/hardhat-kadena
plugin.
In the Ethereum the contract addresses derive from msg.sender + nonce. Since nonce changes for each transaction, that makes contract addresses unpredictable. create2 solves this issue. However, the create2 opcode can only be used from soldity (or Yul) code. We therefore need a create2 factory in order to have the same address on all chains.
This plugin creates a single purpose key from the deployer key and uses that key only for deploying the create2Factory, not any other type of tx. This way the nonce will always be 0 for a new create2 factory deployment. That means that the resulting create2 factory address stays the same on all chains.
For Create2Factory to maintain the same address across all chains:
Never use the derived secondary key for any other transactions
Use the same signer and version when deploying to new chains
Keep your original signer safe
Version parameter
npm install @kadena/hardhat-create2-proxy
# or
yarn add @kadena/hardhat-create2-proxy
# or
pnpm install @kadena/hardhat-create2-proxy
hardhat.config.ts
(or .js
):import '@kadena/hardhat-chainweb';
module.exports = {
solidity: '0.8.20',
chainweb: {
hardhat: {
chains: 3, // Creates a 3-chain network
},
},
};
import { chainweb } from 'hardhat';
// deploy your create 2 proxy on all chains if not deployed;
const create2Factories = await chainweb.create2.deployCreate2Factory();
// create2Factory[0].contract // factory deployed on the first chain
// create2Factory[2].contract // factory deployed on the second chain
// deploy your contract on all chains
const { deployments } = await chainweb.create2.deployOnChainsUsingCreate2({
name: 'SimpleToken',
constructorArgs: [ethers.parseUnits('1000000')],
});
// deployments[0].contract // deployed contract on first chian
The plugin adds create2
property to hre.chainweb
the Hardhat Runtime Environment (HRE):
export interface Create2Helpers {
// deploy create2Factory contract by using the signer key. the default value is the hardhat first account
// use version if you want to deploy a fresh create2factory
deployCreate2Factory: (props?: {
signer?: Signer;
version?: number | bigint;
}) => Promise<
[
contractAddress: string,
deployments: {
contract: unknown;
address: string;
chain: number;
deployer: string;
network: {
chainId: number;
name: string;
};
}[],
]
>;
// returns create2Factory address by using the signer key. the default value is the hardhat first account
// version default value is 1 you can set something else if you deployed different version
getCreate2FactoryAddress: (props?: {
signer?: Signer;
version?: number | bigint;
}) => Promise<string>;
// deploy the contract using the default create2Factory; if ypu want different proxy you can use the create2Factory property
deployOnChainsUsingCreate2: (args: {
name: string;
signer?: Signer;
factoryOptions?: FactoryOptions;
constructorArgs?: ContractMethodArgs;
overrides?: Overrides;
salt: BytesLike;
create2Factory?: string;
}) => Promise<{
deployments: Array<{
contract: BaseContract & {
deploymentTransaction(): ContractTransactionResponse;
};
address: string;
chain: number;
network: {
name: string;
};
}>;
}>;
}
// Deploy with standard CREATE2 (not bound to sender)
const { deployments } = await chainweb.create2.deployOnChainsUsingCreate2({
name: 'SimpleToken',
constructorArgs: [ethers.parseUnits('1000000')],
salt: 'my_salt',
});
// calculate create2 address in front end side
const predictedAddress = ethers.getCreate2Address(
await getCreate2FactoryAddress(),
salt,
initCode,
);
// deployments[0].address === predictedAddress
// Deploy factory with a specific version
const [create2factoryAddress] = await chainweb.create2.deployCreate2Factory({
version: 2,
});
// deploy the contract using the create2factory
const { deployments } = await chainweb.create2.deployOnChainsUsingCreate2({
name: 'SimpleToken',
constructorArgs: [ethers.parseUnits('1000000')],
salt: 'my_salt',
create2Factory: create2factoryAddress,
});
// get create2 address for version 2 factory
const predictedAddress = ethers.getCreate2Address(
await getCreate2FactoryAddress({ version: 2 }),
salt,
initCode,
);
For more comprehensive examples of using the CREATE2 functionality, see the test cases in the SimpleToken.test.ts file. These tests demonstrate:
This project is licensed under the MIT License.
FAQs
Hardhat plugin for deploying deterministic create2Factory contract
We found that @kadena/hardhat-kadena-create2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.