>> Smart contracts extend a block chain from data to code.
They represent an agreement between parties,
and that agreement is coded and when an action happens,
the code is executed and provides a response.
All of the terms and conditions of
the smart contracts are programmatically defined.
The definition specifies the rules,
requirements, and rewards for those who participate.
They execute on their own,
send events, call functions, and more.
Smart contracts are great ways to do business
because they provide autonomy, trust,
savings because of the direct transactions
without a third-party, safety, and efficiency.
The most prominent use of smart contracts is with Ethereum,
the world's programmable blockchain
that allows for smart contracts to be
defined and help facilitate
the transfer of digital assets like Ether.
They can also generate their own currency and tokens to transfer,
and thy use cases are expanding well beyond cryptocurrency.
Now, let me demonstrate
an example smart contract where we
can create a contract called Coin,
which implements a simple cryptocurrency.
With this currency, we'll be able to create and send coins.
To do that, I'll be using
a web-based integrated development environment called Remix.
Remix is really quick to get started without needing an account.
You can really quickly and easily develop,
test, build, and deploy solidity contracts.
I'll visit remix.ethereum.org to get started.
When my browser goes to this page,
the first thing I notice is that I'm taken to this view.
On my left, I see the file explorers,
and I notice that there are already three contracts
available there as well as that test.
I can use those three contracts to help learn, and explore,
and interact with to learn a little bit more
about smart contracts as well as solidity.
I encourage you to check those out on your own.
What I'm going to do in this video is demonstrate adding
a new file and talk through what's
happening in this new smart contract called Coin.
To do that, I will click on this plus button and
create a new file called Coin.sol.
S-O-L gives that the Solidity file extension type.
After creating this new file called Coin.sol,
what I'm going to do is bring in the code for this Coin contract.
Since things are a little crowded over here,
let me close the file explorer and focus in on the contract.
With this contract, what I start with at
the top is this pragma directive.
The pragma is going to specify
a specific version of solidity to be compiled against.
Then on line 4 is going to be my contract definition.
To define a new contract,
I always want to use the keyword contract and then give it a name.
Then, within this contract,
let's take a look at what's happening.
In this contract, I have two state variables.
First is of the minter.
This minter has an address,
which is going to be a 20-byte value
that uniquely assigns this user.
Next, there is a mapping of balances.
What I do is provide
an address and then returned an unsigned integer.
If I pass in the address of the minter,
I can be able to get their balance back as a result.
Next, I define an event called the Sent,
which takes a from address,
a to address, and an amount.
Then there is a constructor.
This constructor is called when the contract is created.
This [inaudible] and assigns the minter the role of
message.sender who is going to be the
one sending the messages in this contract.
Then, I have two functions.
The first function is mint.
This mint function takes
a address receiver and specifies an amount.
Also, notice that this is a public function.
Within the body of this function,
I have a requirement,
first to check the message sender is the minter,
and then require that the amount is less
than this extra large amount here.
Then what I can do is mint,
actually create an amount of coins to
mint to send to the receiver this specific amount.
Then the function sent takes an address and an amount.
This is also a public function.
First, it checks that the amount
sent is less than the total balance of the message sender.
Then what it does is decrement the amount from
the message sender and add the amount to the receiver.
Finally, in this last line, emit Sent.
What we're doing here is emitting the sent event.
This line will be visible on
the EVM logs and this will become part of our blockchain.
We will always be able to see what was sent to who and the amount.
This is a very simple contract in Solidity that
allows us to create some simple currency called Coin.
[MUSIC]