I want to deploy a simple smart contract from frontend using contracFactory (https://docs.ethers.io/v5/api/contract/contract-factory/).
I have been trying in different opportunities for around a year now, without sucess.Im having such a hard time that Im wondering if is this even posible?? or my approach is not correct.
Generally I test in remix and I copy the abi and the bytecode from remix aswell…
here is an example
async function contractdeploy(){
let abi = ( HERE I PASTED THE BYTECODE I COPIED FROM REMIX)
let bytecode = ( HERE I PASTED THE ABI I COPIED FROM REMIX)
const ethers = Moralis.web3Library;
const provider = await Moralis.enableWeb3()
let factory = new ethers.ContractFactory(abi, bytecode, provider);
let contract = await factory.deploy("Hello World");
console.log(contract.address);
console.log(contract.deployTransaction.hash);
await contract.deployed()
}
PS. just in case here is the demo contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
contract HelloWorld {
string public message;
constructor(string memory initMessage) {
message = initMessage;
}
function update(string memory newMessage) public {
message = newMessage;
}
}