2 years ago
#73648
Leo
Hardhar Deploy solidity smart contract using onClick event in React
I would like to deploy my contract in frontend after a user click on a button. In hardhat documentation, I would have to normally run npx hardhat run scripts/deploy.js
in my terminal to deploy. Is it possible to deploy in the frontend?
The code below is something I would like to do.
const hre = require("hardhat") // this will cause error
const deployClick = async () => {
setIsNoClicked(true);
const ticketContract = await hre.ethers.getContractFactory("Greeter");
const ticket = await ticketContract.deploy("Hello, Hardhat!");
await ticket.deployed();
console.log("Ticket Contract deployed to:", ticket.address);
}
javascript
reactjs
solidity
hardhat
0 Answers
Your Answer