Hardhat plugin to deploy your smart contracts across multiple Ethereum Virtual Machine (EVM) chains with the same deterministic address.
This repo is a fork of xdeployer
It enables smart contract deployment through the CREATE2 EVM opcode. CREATE2 can be used to compute in advance the address where a smart contract will be deployed. It also decorelates the contract deployment address from the user nonce.
This plugin is used by The RN library to perform some contract deployments.
npm install --save-dev request-xdeployer @nomiclabs/hardhat-ethers @openzeppelin/contractsOr if you are using Yarn:
yarn add --dev @requestnetwork/xdeployer @nomiclabs/hardhat-ethers @openzeppelin/contractsNote: This plugin uses the optional chaining operator (
?.). Optional chaining is not supported in Node.js v13 and below.
In your hardhat.config.ts:
import"@requestnetwork/xdeployer";This plugin does not extend the environment.
TypeScript configuration in your hardhat.config.ts:
constconfig: HardhatUserConfig={networks: {mainnet: { ... }},xdeploy: {salt: "YOUR_SALT_MESSAGE",signer: "SIGNER_PRIVATE_KEY",networks: ["LIST_OF_NETWORKS"],rpcUrls: ["LIST_OF_RPCURLS"],gasLimit: "GAS_LIMIT",deployerAddress: "0x..."},};The parameter gasLimit and deployerAddress are optional. If deployerAddress is undefined the plugin will use the default deployer contract: for more information refer to the main repo
The salt parameter is a random value (32 byte string) used to create the contract address. If you have previously deployed the same contract with the identical salt, the contract creation transaction will fail due to EIP-684. For more details, see also here.
Example of configuration:
xdeploy: {salt: "WAGMI",signer: process.env.PRIVATE_KEY,networks: ["hardhat","rinkeby","kovan"],rpcUrls: ["hardhat",process.env.RINKEBY_URL,process.env.KOVAN_URL],gasLimit: 1.2*10**6,},To use this plugin in your code run:
constdeploymentParams={contract: "MyContract",constructorArgs: [true,50,"example"]}constdeploymentResult=awaithre.run('xdeploy',deploymentParams)Deployment result format:
interfaceIDeploymentResult{network: string;// Name of the network the contract was deployed oncontract: string;// Name of the deployed contractaddress: string|undefined;// Address of the newly deployed contract (if deployment successfull)receipt: any;// Receipt of the transation deployed: boolean;error: string|undefined;// Error if any}