📜

Adding a New Contract

TL;DR ..... (To be added)
If we open http://localhost:3000 we should see YourContract.sol displayed.
​​
Screen Shot 2021-08-24 at 12 28 21 PM
​
​
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.
​​
Screen Shot 2021-08-24 at 12 39 30 PM
​
​
Now we can add a new <Contract /> component to our frontend at the "/" path in our App.jx located at packages/react-app/src.
​​
Screen Shot 2021-08-24 at 12 41 01 PM
​
​
Run yarn deploy to deploy NewContract.sol and we should see our new contract displayed on the frontend!
​​
Screen Shot 2021-08-24 at 1 14 54 PM
​
​
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!