0% found this document useful (0 votes)
10 views1 page

Solidity v1

The document provides an introduction to Solidity, a high-level programming language for writing smart contracts on the Ethereum blockchain. It explains the structure and components of smart contracts, including state variables, functions, and visibility types, while highlighting the automatic enforcement of contract rules. Additionally, it covers data types, function modifiers, events, and custom-defined types such as structs and enums.

Uploaded by

xasak44769
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Solidity v1

The document provides an introduction to Solidity, a high-level programming language for writing smart contracts on the Ethereum blockchain. It explains the structure and components of smart contracts, including state variables, functions, and visibility types, while highlighting the automatic enforcement of contract rules. Additionally, it covers data types, function modifiers, events, and custom-defined types such as structs and enums.

Uploaded by

xasak44769
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Introduction to Solidity and Smart Contracts

A smart contract is a A smart contract in A smart contract not only defines the rules and penalties around an agreement in the same
computer program that Ethereum is written in way that a traditional contract does, but it can also automatically enforce those obligations.
directly controls the transfer Solidity – a contract-
of digital currencies or oriented, high-level
assets between parties language whose syntax is Contracts in Solidity are similar to classes in object-oriented languages. They contain
under certain conditions. similar to that of JavaScript. persistent data in state variables and functions that can modify these variables .

First line of the code there should be information


about a so-called version pragma Objects
pragma solidity ^0.4.0; Description Example

Values which are

State Variables
contract Coin {
Contracts permanently stored in /* State variable*/
contract storage string public name = 'Cool Coin Token';
The contract is the basic structure of Solidity. It is a prototype // ...
of an object which lives on the blockchain. uint public totalSupply = 0;
address public authority;
// ...
contract Simple { }
uint public x = 2;
Executable units of
Functions
function() { function checkGoalReached() returns (bool) {
var z = x + 2; code within a contract if (now >= deadline ||
// var is “uint” here closeOnGoalReached) {
} if (amountRaised >= fundingGoal){
} fundingGoalReached = true;
GoalReached(beneficiary,
Types }
amountRaised);

if (now >= deadline) {


Data values crowdsaleClosed = true;
• Booleans • Address Literals }
• Integers • Rational and Integer Literals }
Solidity is a statically typed language,
• Address • which
String means
Literalsthat the type return crowdsaleClosed;
of each variable byte
• Fixed-size (statearrays
and local) needs to be specified.
• Hexadecimal Literals }
Objects that can be
Function Modifiers

• Dynamically-sized byte array • Enums modifier onlySeller() { // Modifier


• Fixed Point Numbers • Mappings used to change the if (msg.sender != seller) throw;
semantics of functions _;
Function Types in a declarative way }

function abort() onlySeller {


Function types are the types of functions. Variables of function // Modifier usage
type can be assigned from functions and function parameters of // ...
function type can be used to pass functions to and return }
functions from function calls.
Interfaces with the
Events

contract SimpleAuction {
EVM logging facilities event HighestBidIncreased(address bidder,
• External functions consist of • Internal functions can only uint amount); // Event
an address and a function be used inside the current
signature and they can be contract because they function bid() payable {
passed via and returned cannot be executed outside // ...
from external function calls. of the context of the current HighestBidIncreased(msg.sender,
contract. Calling an internal msg.value); // Triggering event
function is realized by }
jumping to its entry label, }
just like when calling a
Custom defined types
Structs Types

function of the current contract Ballot {


contract internally. that can group several struct Voter { // Struct
Reference Types variables uint weight;
bool voted;
Complex types, i.e. types which do not always fit into 256 bits address delegate;
have to be handled more carefully than the value-types. Since uint vote;
copying them can be quite expensive, we have to think about }
whether we want them to be stored in memory }

Objects that can be


Enum Types

contract Purchase {
Visibility and Getters used to create custom
types with a finite set
enum State { Created, Locked, Inactive }
// Enum
Solidity knows two kinds of function calls (internal ones that do of values }
not create an actual EVM call (also called a “message call”)
and external ones that do), consequently there are four types of
visibilities for functions and state variables.
• external. Part of the contract • public. Part of the contract interface, • internal. These functions and state • private. These functions and state
interface, thatcan be called from the functions can be either called variables can only be accessed, variables are only visible for the
other contracts and via transactions. internally or via messages. For without using this. contract they are defined in and not
An external function f cannot be public state variables, an automatic in derived contracts.
called internally. getter function is generated.

More information

You might also like