๐Ÿ“œ
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.
1
pragma solidity >=0.8.0 <0.9.0;
2
//SPDX-License-Identifier: MIT
3
โ€‹
4
import "hardhat/console.sol";
5
//import "@openzeppelin/contracts/access/Ownable.sol"; //https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol
6
โ€‹
7
contract NewContract {
8
โ€‹
9
//event SetPurpose(address sender, string purpose);
10
โ€‹
11
string public purpose = "Learn Scaffold-eth";
12
โ€‹
13
constructor() {
14
// what should we do on deploy?
15
}
16
โ€‹
17
function setPurpose(string memory newPurpose) public {
18
purpose = newPurpose;
19
console.log(msg.sender,"set purpose to",purpose);
20
//emit SetPurpose(msg.sender, purpose);
21
}
22
}
Copied!
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