Skip to content

Commit 0929825

Browse files
committed
Make textual enhancements from lines 650 to 860
1 parent 42ef6ce commit 0929825

File tree

1 file changed

+22
-22
lines changed
  • pages/lessons/projects

1 file changed

+22
-22
lines changed

pages/lessons/projects/3.mdx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -653,16 +653,17 @@ contract TierNFT is ERC721 {
653653
</details>
654654
<br/>
655655
656-
### Where are all our funds? Add withdraw Function
656+
### Where are all our funds? Let's add a withdraw Function!
657657
658-
We need to find a way to actually withdraw any funds our contract generates, otherwise they'll get stuck **in the contract** .... that we created!
658+
We need to find a way to actually withdraw any funds our contract generates, otherwise they'll get stuck **in the contract** .... that **we** created! Let's import `Ownable.sol`, to get those permissions, so that only **we** can withdraw those funds, and not anyone else. Clever, eh?
659659
660660
```solidity
661661
// Place this next to the other imports at the top:
662662
import "@openzeppelin/contracts/access/Ownable.sol";
663663
````
664664
665-
We import `Ownable.sol`, so that only *we* can withdraw those funds, and not anyone else. Clever, eh?
665+
666+
And inherit `Ownable` from the Open Zeppelin contract into our own.
666667
667668
```solidity
668669
// Modify the contract definition, by adding 'Ownable' at the end of the line:
@@ -674,7 +675,6 @@ contract TierNFT is ERC721, Ownable {
674675
}
675676
```
676677

677-
We inherit `Ownable` from the Open Zeppelin contract into ours.
678678

679679
If your phone is ringing, or someone is knocking at your door right now, ignore all of it! Let’s get this withdraw function coded in here!!
680680

@@ -697,15 +697,15 @@ If your phone is ringing, or someone is knocking at your door right now, ignore
697697
}
698698
```
699699

700-
- `onlyOwner` - You're going to see this modifier a lot. It comes from the Ownable contract we just imported. It's very powerful. It makes
701-
sure that only the account that deployed the contract (owner is assigned on its
702-
constructor) can execute the function that it appears in.
700+
- `onlyOwner` - you're going to see this modifier a lot. It comes from the *Ownable* contract we just imported. It's very powerful. It makes sure that only the account that deployed the contract, i.e. the owner is assigned on its
701+
constructor, can execute the function that it appears in.
702+
- In Solidity, `this` refers to the current contract instance. `address(this)` gets the contract's address, and `.balance` grabs the current balance, which gets stored in `uint256 balance`.
703703
- By checking `uint256 balance = address(this).balance` against `require(balance > 0, "Balance should be > 0");`, we can see if we actually have something to withdraw. And we would hope so, as the function consumes gas. And, as you've probably guessed, it will throw an error otherwise.
704-
- `(bool success, ) = payable(owner()).call{value: balance}("")` - is an actual
704+
- `(bool success, ) = payable(owner()).call{value: balance}("")` is an actual
705705
transfer of funds which uses the whole balance that we checked in the previous
706-
instruction.
706+
instruction. The `owner`'s address can allow the transfer thanks to the `payable()` function. We can leave the `("")` data parameter blank in our case.
707707
- `require(success, "Withdraw failed")` - This is a good practice because
708-
`call` doesn’t revert. With this practice we can make sure that the transfer
708+
the `.call()` function doesn’t revert. With this practice we can make sure that the transfer
709709
occurred and throw an error if it doesn’t.
710710

711711
<br/>
@@ -812,7 +812,7 @@ contract TierNFT is ERC721, Ownable {
812812

813813
We need a script so we can get our smart contract deployed. Let’s write that.
814814

815-
Create a new javascript file named `deploy.js` in the `scripts` folder with this
815+
Create a new Javascript file named `deploy.js` in the `scripts` folder with this
816816
code:
817817

818818
```jsx
@@ -843,22 +843,22 @@ main().catch((error) => {
843843
```
844844

845845
- `CONTRACT_NAME = "TierNFT"` - is the name of our contract, which
846-
will tell Hardhat exactly *what* to deploy.
846+
will tell Hardhat exactly **what** to deploy.
847847
- With `const COLLECTION_NAME = "TierNFT"` and
848-
`const COLLECTION_SYMBOL = "Tier"` - we define the Name and Symbol to pass to the constructor for the deployment.
848+
`const COLLECTION_SYMBOL = "Tier"` - we define the *name* and *symbol* to pass to the constructor for the deployment.
849849
- `hre.ethers.getContractFactory(CONTRACT_NAME)` - this asks Hardhat Runtime
850-
Environment to get us a contract factory for our contract.
851-
- `contractFactory.deploy` - We are asking the contract factory to deploy our
850+
Environment to get us a contract factory for our contract specified by `CONTRACT_NAME`. A contract factory is a template that allows us to deploy instances of that contract.
851+
- `contractFactory.deploy` - we are asking the contract factory to deploy an instance of our
852852
contract. This is the deploy transaction!
853-
- `COLLECTION_NAME, COLLECTION_SYMBOL` - These are the parameters for our
854-
contract's constructor function.
855-
- `await contract.deployed()` - It waits for the transaction to be approved and our
856-
contract is finished deploying.
857-
- The `main().catch( … )` at the very end makes sure that all the previous
858-
code is executed when this script is run, and also prints any errors to the console.
853+
- `COLLECTION_NAME, COLLECTION_SYMBOL` - these are the parameters for our
854+
contract's constructor function to set up its initial state.
855+
- `await contract.deployed()` - waits for the transaction to be approved and our
856+
contract to be finished deploying.
857+
- Running the `main().catch( … )` script at the very end makes sure that all the previous
858+
code is executed, and also logs any errors, and prints them to the console.
859859

860860

861-
### Time to DEPLOY but also some changes
861+
### Time to deploy, but first some changes
862862

863863
Now the time has come for us to deploy our smart contract. But before we can do
864864
that, we need to modify the code in `hardhat.config.js` placed in our root folder to this:

0 commit comments

Comments
 (0)