You are on page 1of 13

Intro To Solidity

Travis Herrick
What is Solidity?

● Solidity is the language we use the write Ethereum code


● Vitalik built Ethereum to be a Blockchain where we can write
arbitrary instructions, called a Smart Contract
● Solidity is a Turing-Complete language, unlike most other
blockchains (Bitcoin, etc)
● Smart Contracts allow us to execute code on this world
computer, which we pay for in Gas
Hello Solidity
pragma solidity 0.4.18;

contract Example {
address public owner;
string public message;

function Example(string _message) public {


owner = msg.sender;
message = _message;
}

function getMessage() public constant returns (string _message) {


return message;
}

function exclaim() public returns (string _message) {


message = message + "!";
return message;
}
}
Where does this code run?

On a Blockchain, of course!
pragma solidity 0.4.18;

contract Example {
address public owner;
string public message;

function Example(string _message) public {


owner = msg.sender;
message = _message;
}

function getMessage() public constant returns (string _message) {


return message;
}

function exclaim() public returns (string _message) {


message = message + "!";
return message;
}
}
pragma solidity 0.4.18;

contract Example {
address public owner;
string public message;

function Example(string _message) public {


owner = msg.sender;
message = _message;
}

function getMessage() public constant returns (string _message) {


return message;
}

function exclaim() public returns (string _message) {


message = message + "!";
return message;
}
}
Transactions

● When you call a write function, you’re calling a transaction on


a blockchain
● Transactions are Asynchronous
● Transactions are either function calls or deploying contracts
● Part of writing transactions to a block is to verify they are well
formed, and this includes running the actual solidity code. All
nodes must do this.
Gas - You do have to pay for it.
Gas

● You have to pay for:


○ Computation
○ Storage
○ Network
● Gas is not a transaction fee - gas is a measure of how much
work you are asking the world computer to do.
Gas Costs
pragma solidity 0.4.18;

contract Example {
address public owner;
string public message;

function Example(string _message) public {


owner = msg.sender;
message = _message;
}

function getMessage() public constant returns (string _message) {


return message;
}

function exclaim() public returns (string _message) {


message = message + "!";
return message;
}
}
Smart Contracts

● Smart Contracts are written to a blockchain, and have


addresses just like an account
● We send function calls to these addresses just like we would
send cryptocurrency to a public address
● We can deploy the same contract to Ethereum multiple times
Questions?

You might also like