Deploying Contract
import { ethers } from "ethers";
async function deployContract() {
// Replace with your Ethereum node's RPC endpoint
const RPC_URL = "https://demouser:[email protected]/rpc";
// Connect to your Ethereum node
const provider = new ethers.JsonRpcProvider(RPC_URL);
// Replace these values with your contract's ABI and bytecode
const contractAbi = []; // Your contract's ABI as an array
const contractBytecode = ""; // Your contract's bytecode as a hex string
// Set the account that will deploy the contract
const privateKey = ""; // Replace with the private key of the account deploying the contract
const wallet = new ethers.Wallet(privateKey, provider);
console.log(`wallet address: ${wallet.address} bal: ${await provider.getBalance(wallet.address)}`);
// Create a contract factory
const MyContractFactory = new ethers.ContractFactory(contractAbi, contractBytecode, wallet);
console.log("contract ready to deploy");
// Deploy the contract
const MyContract = await MyContractFactory.deploy(10);
// Wait for the contract to be mined
await MyContract.waitForDeployment();
console.log("contract deployed");
console.log(`Contract deployed successfully at address: ${await MyContract.getAddress()}`);
}
deployContract();
Last updated
Was this helpful?