๐Ÿ“œ
Adding a New Contract
TL;DR ..... (To be added)
If we open http://localhost:3000 we should see YourContract.sol displayed.
โ€‹โ€‹
โ€‹
โ€‹
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!
Copy link