Created
April 23, 2023 01:14
-
-
Save ccolorado/deed1ebbd0176be19a130b0f551fa311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers'); | |
const solc = require('solc'); | |
const fs = require('fs'); | |
const bytecode = fs.readFileSync('path/to/bytecode').toString(); | |
const abi = JSON.parse(fs.readFileSync('path/to/abi')); | |
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545'); // Initialize Ethers provider | |
const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider); // Initialize signer | |
async function deployContract(salt, ...args) { | |
const factory = new ethers.ContractFactory(abi, bytecode, signer); | |
const create2 = ethers.utils.solidityKeccak256(['bytes', 'bytes32'], ['0xff', signer.address, salt, ethers.utils.keccak256(bytecode)]); | |
const deployedContract = await factory.deploy(create2, ...args); | |
await deployedContract.deployed(); | |
return deployedContract; | |
} | |
const salt = '0xYOUR_SALT'; | |
const args = [arg1, arg2, arg3]; // Contract constructor arguments | |
deployContract(salt, ...args) | |
.then(contract => console.log(`Contract deployed at address: ${contract.address}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment