Commit 9a3fc1f9 authored by Chris's avatar Chris
Browse files

Completed Solidity intro part 5: Units

parent 7e00a767
Loading
Loading
Loading
Loading
+47 −11
Original line number Diff line number Diff line
@@ -4,11 +4,11 @@

Covers getting started: using Remix, creating smart contracts

### Video link
### Part 1 video link

https://www.youtube.com/watch?v=sngKPYfUgkc&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo
<https://www.youtube.com/watch?v=sngKPYfUgkc&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo>

### Notes
### Part 1 notes

- Remix: allows you to write Solidity code; allows you to write, compile, and run the code on eth blockchain
  - remix.ethereum.org
@@ -35,11 +35,11 @@ contract SampleContract {

Covers variable types

### Video link
### Part 2 video link

<https://www.youtube.com/watch?v=C70XrG5yGQo&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo&index=2>

### Notes
### Part 2 notes

- keep usage of strings to a minimum: strings are bytes bundled together, which means they can cost a lot of gas when used in smart contracts
  - keep usage of strings to a minimum and rely on primitve types instead
@@ -67,11 +67,11 @@ Covers variable types

continuing usage of variables with more interesting concepts, covering the `address` type

### Video link
### Part 3 video link

https://www.youtube.com/watch?v=AFma5JYgIIE&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo&index=4
<https://www.youtube.com/watch?v=AFma5JYgIIE&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo&index=4>

### Notes
### Part 3 notes

- address types were created, but they should properly be typecasted (are they really primitives then...?)
  - `address public myAddress = address(...)`
@@ -104,11 +104,47 @@ https://www.youtube.com/watch?v=AFma5JYgIIE&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05

this tutorial talks about operators you can use in Solidity

### Video link
### Part 4 video link

https://www.youtube.com/watch?v=KlO23rhqEnw&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo&index=5
<https://www.youtube.com/watch?v=KlO23rhqEnw&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo&index=5>

### Notes
### Part 4 notes

- see **MyOperators.sol** for a list of operators you can use
- a **view function** is a function that does not change state: use keyword to help compiler and readability

## Part 5

this tutorial talks about measurement units (wei, gwei, ether) available in Solidity

### Part 5 video link

<https://www.youtube.com/watch?v=64SiCO_GzDo&list=PLvfQp12V0hS2PQd9-X-E2AjmXj1o05WOo&index=6>

### Part 5 notes

- smart contracts always work with the unit **wei**
  - review:
    - 1 wei == 1
    - 1 gwei == 1e9
    - 1 ether == 1e18
- so you can actually just do this:

```solidity
uint256 costOfNFT = 0.05 ether;
```

- you also get units with time
  - 1 == 1 seconds
  - 1 minutes == 60 seconds
  - 1 hours == 60 minutes
  - 1 days == 24 hours
  - 1 weeks == 7 days

- let's talk about gas
- gas is the unit of computation in Solidity
  - the unit of computation on the Ethereum blockchain
- gas price is defined as the amount you are willing to pay for a gas unit
- price of the gas is usually set, and the higher the gas price, the higher priority it will be to be mined first
  - higher the gas price -> higher the tx fee, and the quicker it gets mined on the block
- the gas spent is usually on the transaction: how long it took for the contract to run through the program and execute what it needed to execute