Skip to content

Instantly share code, notes, and snippets.

@ccolorado
Created April 23, 2023 01:14
Show Gist options
  • Save ccolorado/deed1ebbd0176be19a130b0f551fa311 to your computer and use it in GitHub Desktop.
Save ccolorado/deed1ebbd0176be19a130b0f551fa311 to your computer and use it in GitHub Desktop.
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