📜
Adding a New Contract
TL;DR ..... (To be added)
YourContract.sol
lives in packages/hardhat/contracts
.Let's add a new contract. Begin by creating a new file
NewContract.sol
in packages/hardhat/contracts
.We can easily populate the file by copy and pasting
YourContract.sol
, changing the contract name, and maybe changing the purpose
variable.pragma solidity >=0.8.0 <0.9.0;
//SPDX-License-Identifier: MIT
import "hardhat/console.sol";
//import "@openzeppelin/contracts/access/Ownable.sol"; //https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol
contract NewContract {
//event SetPurpose(address sender, string purpose);
string public purpose = "Learn Scaffold-eth";
constructor() {
// what should we do on deploy?
}
function setPurpose(string memory newPurpose) public {
purpose = newPurpose;
console.log(msg.sender,"set purpose to",purpose);
//emit SetPurpose(msg.sender, purpose);
}
}
Once we have saved
NewContract.sol
let's add it to our deployment in packages/hardhat/deploy/00_deploy_your_contract.js
.Now we can add a new
<Contract />
component to our frontend at the "/"
path in our App.jx
located at packages/react-app/src
.Run
yarn deploy
to deploy NewContract.sol
and we should see our new contract displayed on the frontend!We've just learned how to quickly implement and deploy a new contract in scaffold-eth 🚀 We can start pulling in other contracts and playing with functionality blazing fast 🔥 Boom! Middle rolls!
Last modified 1yr ago