SlideShare a Scribd company logo
Understanding Algorand’s
Smart Contract Language
● Agenda
○ Overview of the types of smart contracts
■ Stateless Contracts
■ Stateful Contracts
■ Combining with other Algorand Technologies
○ Runtime Architecture
■ Stateless
■ Stateful
○ TEAL - Algorand Smart Contract Language
■ Opcodes and Examples
○ PyTeal and Reach
Algorand Smart Contracts
Algorand Smart Contracts - Layer 1
Smart Contract
Contract or Escrow Delegation Application
Stateless Stateful
Escrow/Contract Account Stateless
Smart Contract -
Compiled Logic
Becomes an Account
Standard/Multisig
Account
Standard/Multisig
Account
Standard/Multisig
Account
Fund Account With
Standard
Transactions
Assets/Algos
Spend Transactions
Gated by TEAL
Program
Standard/Multisig
Account
TEAL
Logic
Delegate Stateless
Smart Contract - Logic
Standard/Multisig
Account
Spend Transactions
Gated by TEAL
Program
Standard/Multisig
Account
TEAL
Logic
Standard Transaction Sign
Transaction
Sign TEAL
Logic
Later
Logic Signature
Stateless Contract Usages
• Contract Accounts
• Escrows
• HTLC
• Split Payments
• Limit Orders
• Delegated
• Recurring Payments
• Limited Account Authority
Stateful aka Apps
Application Transaction
Smart
Contract
Logic
Global State
Local State User 1
Local State User 1
Local State User 1
Local State User 1
Approval Program
Clear Program
Smart
Contract
Logic
Deployed Stateful Contract Returns
APPID
Communicate with Application
Transactions
New Transaction Sub-Types for Application
NoOp
TEAL Logic
Modify Local
or Global
state
TEAL Logic
Modify Local
or Global
state
Approval Program
Clear Program
Optin
DeleteApplication
UpdateApplication
CloseOut
Clear
Used to Communicate With Stateful Smart Contract
Graceful
Non-Graceful
ie Will clear
regardless
Stateful Contract Usages
• Defi Apps (AMM, lending, etc)
• Crowdfunding
• Voting
• Material Tracking
• Lottery
• Seating
• Identity Restrictions
• Anywhere a global variable is needed
• Anywhere a individual users values need to be manipulated
Stateful vs Stateless Differences
Stateful Stateless
Evaluation Block Assembly Submission
Size 1kb 1000 bytes
Opcodes 700/Program 20000
Access to Ledger Facilitates Assets/Account
Lookups
Only Tx Based Values
Track State Values Yes No
Logic Lives on Chain Submitted with Tx(s)
Templates Not Currently Yes (HTLC, Split, etc)
Combining Algorand
Technologies
CrowdFunding App Donation Operation
Stateful
Contract
App
Global State
Fund Start Date
Fund End Date
Fund Goal
Fund Amount
Escrow Address
Creator Address
Receiver Address
Fund Close Date
Stateless
Contract
Escrow
Holds All Donations
Donate
Transaction 2 -
Payment Tx
From Donator to
Escrow Account
Transaction 1
Stateful App
Transaction
Atomic Local Storage
Giving Amount
Voting App - Vote Operation
Spend Vote
Token
Receive Vote
Token From
Commission
Global State
Registration Begin
Round
Registration End Round
Vote Begin Round
Vote End Round
Candidate A Votes
Candidate B Votes
Vote Creator
Stateful
Contract
App
Transaction 2 -
Asset Xfer
From Voter to
Commision Account
Transaction 1
Stateful App
Transaction
Atomic
Vote Commission
Runtime Architecture
Stack
Runtime
Stateless Runtime Architecture
Global Vars
Transaction(s)
Properties
Read Only
Temporary
Scratch
Read/Write
TEAL
Program
Arguments
Per Transaction
Transaction Submission
Teal Stack Architecture (Stateless)
#pragma version 3
txn Receiver
addr SOEI...
==
&&
arg 0
len
int 32
==
&&
arg 0
sha256
byte base64 VeU...
==
&&
...
Program
uint64/[]byte
uint64/[]byte
uint64/[]byte
Stack
…(up to 1000)
0: uint64/[]byte
1: uint64/[]byte
2: uint64/[]byte
Scratch Space
...
255: uint64/[]byte
0: []byte
1: []byte
2: []byte
Args
(This txn only)
…(up to 255)
● Sender
● Fee
● FirstValid
● FirstValidTime
● LastValid
● Note
● Lease
● Receiver
● Amount
● CloseRemainderTo
● VotePK
● SelectionPK
● VoteFirst
● VoteLast
● VoteKeyDilution
● Type
● TypeEnum
● XferAsset
● AssetAmount
● AssetSender
● AssetReceiver
● AssetCloseTo
● GroupIndex
● TxID
Transaction(s)
Stateful Contract Runtime
Stateful Runtime Architecture
Global Vars
Transaction(s)
Properties
Read Only
Stack
TEAL
Program(s),
Loaded on
Create
Update
Application
Array - limit
2
Arguments
Array
Per Transaction
Transaction Submission
Accounts
Array - limit
4
Temporary
Scratch
Read/Write
Global/Local
State
Assets Array
- limit 2
Teal Stack Architecture (Stateful)
#pragma version 3
byte "myarg"
txn ApplicationArgs 0
==
bz no_local
int 0
byte "test"
app_local_get
pop
no_local:
// read global state
byte "counter"
app_global_get
...
Program
uint64/[]byte
uint64/[]byte
uint64/[]byte
Stack
…(up to 1000)
0: uint64/[]byte
1: uint64/[]byte
2: uint64/[]byte
Scratch Space
...
255: uint64/[]byte
Transaction(s)
[]byte
[]byte
[]byte
Arguments*
…(up to 16 & 2K)
uint64
uint64
Applications*
…(up to 2 app ids)
[]byte
[]byte
Accounts*
…(up to 4 accounts)
Global State 64
K/V pairs 64
bytes
Local State 16
K/V pairs 64
bytes
* Can change per transaction
● Sender
● Fee
● FirstValid
● FirstValidTime
● LastValid
● Note
● Lease
● Receiver
● Amount
● CloseRemainderTo
● VotePK
● SelectionPK
● VoteFirst
● VoteLast
● VoteKeyDilution
● Type
● TypeEnum
● XferAsset
● AssetAmount
● AssetSender
● AssetReceiver
● AssetCloseTo
● GroupIndex
● TxID
uint64
uint64
Assets*
…(up to 2 asset ids)
TEAL
TEAL - Transaction Execution Approval Language
● Bytecode based stack language
● Returns True or False (One Positive Value Left on
Stack)
● SDK Support
● > 80 Opcodes
● Access to ASA/Algo Balances
● Read all Transactions in a Group
● Stateful - Global/Local Storage Calls
● Stateless - Signature Verification
● PyTEAL library to write in python
Push Pop
Simple Stack Example
txn Amount
int 1000
>=
Transaction Amount
txn Amount
int 1000
>=
1
1000
Transaction Amount
txn Amount
int 1000
>=
2
txn Amount
int 1000
>=
T
r
a
n
s
a
c
t
i
o
n
A
m
o
u
n
t
3
1
0
0
0
0/1
Transaction Amount >= 1000
Opcodes
Opcode Reference Document
Pseudo Operators
int //load an int onto stack
byte //Load bytes on stack
addr //Load Algorand address
TEAL Approval Program
txn Receiver
addr HJLWACXDBOEH25KJB2WI2X5BHQOJ4LS2MRLNMHJ5ZZOBLJU7KGDJSHEU3I
==
.
byte “mystring”
txn ApplicationArgs 0
==
State Demo
Branching Demo - b, bnz,
bz
Accessing Transaction Properties
TEAL Approval
Program
txn Amount
int 1000
>=
● Sender
● Fee
● FirstValid
● FirstValidTime
● LastValid
● Note
● Lease
● Receiver
● Amount
● CloseRemainderTo
● VotePK
● SelectionPK
● VoteFirst
● VoteLast
● VoteKeyDilution
● Type
● TypeEnum
● XferAsset
● AssetAmount
● AssetSender
● AssetReceiver
● AssetCloseTo
● GroupIndex
● TxID
Global Variables
Checking Type of Transaction
TEAL Approval
Program
txn TypeEnum
int appl
==
Application Transaction Sub-Types - Stateful
TEAL Approval
Program
txn OnCompletion
int NoOp
==
Atomic Transactions - gtxn vs txn
Transaction 1
Call to Stateful Contract
Transaction 2
Payment Transaction
Transaction 3
Asset Transfer Transaction
Atomic TEAL Approval Program
global GroupSize
int 3
==
gtxn 0 TypeEnum
int appl
==
&&
gtxn 1 TypeEnum
Int pay
==
&&
gtxn 2 TypeEnum
axfer
==
&&
Atomic Demo
Asset Check
TEAL Approval Program
int 0 //Sender of tx
int 2 //asset id
asset_holding_get AssetBalance
pop //assume they have the asset
int 1
>=
Transaction 1
Call to Stateful Contract
Read Global State From Another Contract
Readonly
Read Other Contracts State
Demo
Reading and Writing Local State
int 0 //sender
byte "MyAmountGiven"
txn Amount
app_local_put
int 0 //sender
byte "MyAmountGiven"
app_local_get
int 1 //Account 1
int 1234 //other contract id
byte “OtherContractKey”
app_local_get_ex
Account 1
Account 2
Accounts
Transaction 1
Call to Stateful Contract
Account 3
Account 4
Sender
Local State 16 K/V
pairs 64 bytes
Account 1
Local State 16 K/V
pairs 64 bytes
Local State 16 K/V
pairs 64 bytes
Account 4
Read/Write
Read Only
Account 4
Local State 16 K/V
pairs 64 bytes for
Different Contract
Local State 16 K/V
pairs 64 bytes for
Different Contract
Sender
Escrow Demo
Simplifying Smart Contract
Development
Smart Contract Options
TEAL
PyTeal
Compiler
Reach Application
Business
Logic TEAL
TEAL
TEAL
TEAL
def bank_for_account(receiver):
is_payment = Txn.type_enum() == TxnType.Payment
is_single_tx = Global.group_size() == Int(1)
is_correct_receiver = Txn.receiver() == Addr(receiver)
return And(
is_payment,
is_single_tx,
is_correct_receiver
)
if __name__ == "__main__":
program =
bank_for_account("ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFL
XXD3PFSNJJBYAFZM")
print(compileTeal(program, Mode.Signature))
PyTEAL -Python Library
Returns
#pragma version 2
txn TypeEnum
int pay
==
global GroupSize
int 1
==
&&
txn Receiver
addr
ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3P
FSNJJBYAFZM
==
&&
PyTeal Documentation
Documentation
Reach - Reach.sh
Reach Documenation
Follow Guidelines for Safety
Boilerplate Approval Program
Example Stateless Contract
Adhere to These Guidelines to Protect Accounts
Size Limitations and Opcode Cost Limits
Presentation and Examples
https://github.com/algorand/smart-contracts/tree/master/devrel/demo
Resources
● Discord: https://discord.gg/YgPTCVk
● Developer Portal (Documentation and Tutorials):
https://developer.algorand.org/
● Forum: https://forum.algorand.org/
● GitHub: https://github.com/algorand
● OFFICE HOURS sign up:
https://www.algorand.com/developers

More Related Content

What's hot

QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
ICS
 
Algorand
AlgorandAlgorand
Algorand
atousa_ahsani
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1
Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1
Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1
Gilbert Verdian
 
ERC20 Step-by-Step - Creating Your First Ethereum Token
ERC20 Step-by-Step - Creating Your First Ethereum TokenERC20 Step-by-Step - Creating Your First Ethereum Token
ERC20 Step-by-Step - Creating Your First Ethereum Token
CodeOps Technologies LLP
 
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart Contracts
Techracers
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
Bhalaji Nagarajan
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Edureka!
 
Introduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for DevelopersIntroduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for Developers
R3
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
ShubhamMishra485
 
All About Ethereum
All About EthereumAll About Ethereum
All About Ethereum
Oodles Technologies Pvt. Ltd.
 
Smart contract
Smart contractSmart contract
Smart contract
Akhmad Daniel Sembiring
 
Smart contracts
Smart contractsSmart contracts
Smart contracts
Philippe Camacho, Ph.D.
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
ICS
 
MQTT Protocol: IOT Technology
MQTT Protocol: IOT TechnologyMQTT Protocol: IOT Technology
MQTT Protocol: IOT Technology
Shashank Kapoor
 
Ethereum
EthereumEthereum
Smart contractjp smartcontract_about
Smart contractjp smartcontract_aboutSmart contractjp smartcontract_about
Smart contractjp smartcontract_about
Tomoaki Sato
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU
Sergey Aganezov
 
Algorand Technical Workshop 2021
Algorand Technical Workshop 2021Algorand Technical Workshop 2021
Algorand Technical Workshop 2021
DanielBohnemann
 
Python for kids - 1.pptx
Python for kids - 1.pptxPython for kids - 1.pptx
Python for kids - 1.pptx
sanyam1427
 

What's hot (20)

QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Algorand
AlgorandAlgorand
Algorand
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1
Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1
Quant Overledger for Mobility, IOT and Automotive sectors - MOBI 20190220 v1
 
ERC20 Step-by-Step - Creating Your First Ethereum Token
ERC20 Step-by-Step - Creating Your First Ethereum TokenERC20 Step-by-Step - Creating Your First Ethereum Token
ERC20 Step-by-Step - Creating Your First Ethereum Token
 
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart Contracts
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
 
Introduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for DevelopersIntroduction to Corda Blockchain for Developers
Introduction to Corda Blockchain for Developers
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
 
All About Ethereum
All About EthereumAll About Ethereum
All About Ethereum
 
Smart contract
Smart contractSmart contract
Smart contract
 
Smart contracts
Smart contractsSmart contracts
Smart contracts
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
MQTT Protocol: IOT Technology
MQTT Protocol: IOT TechnologyMQTT Protocol: IOT Technology
MQTT Protocol: IOT Technology
 
Ethereum
EthereumEthereum
Ethereum
 
Smart contractjp smartcontract_about
Smart contractjp smartcontract_aboutSmart contractjp smartcontract_about
Smart contractjp smartcontract_about
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU
 
Algorand Technical Workshop 2021
Algorand Technical Workshop 2021Algorand Technical Workshop 2021
Algorand Technical Workshop 2021
 
Python for kids - 1.pptx
Python for kids - 1.pptxPython for kids - 1.pptx
Python for kids - 1.pptx
 

Similar to Understanding Algorand's smart contract language

Ethereum
EthereumEthereum
Ethereum
Brian Yap
 
Ethereum Contracts - Coinfest 2015
Ethereum Contracts - Coinfest 2015Ethereum Contracts - Coinfest 2015
Ethereum Contracts - Coinfest 2015
Rhea Myers
 
Algorand August Release
Algorand August ReleaseAlgorand August Release
Algorand August Release
Russ Fustino
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
عطاءالمنعم اثیل شیخ
 
Ethereum
EthereumEthereum
Ethereum
V C
 
Blockchain Programming
Blockchain ProgrammingBlockchain Programming
Blockchain Programming
Rhea Myers
 
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Gene Leybzon
 
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Simone Onofri
 
Hello world contract
Hello world contractHello world contract
Hello world contract
Gene Leybzon
 
Building Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart ContractBuilding Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart Contract
Vaideeswaran Sethuraman
 
Smart Contracts with Solidity hands-on training session
Smart Contracts with Solidity hands-on training session  Smart Contracts with Solidity hands-on training session
Smart Contracts with Solidity hands-on training session
Gene Leybzon
 
A living programming environment for a living blockchain
A living programming environment for a living blockchainA living programming environment for a living blockchain
A living programming environment for a living blockchain
Santiago Bragagnolo
 
A living programming environment for blockchain
A living programming environment for blockchainA living programming environment for blockchain
A living programming environment for blockchain
Pharo
 
Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618
Arnaud Le Hors
 
Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...
Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...
Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...
Flink Forward
 
Corvil App Agent
Corvil App AgentCorvil App Agent
Corvil App Agent
Corvil
 
1. ibm blockchain explained
1. ibm blockchain explained1. ibm blockchain explained
1. ibm blockchain explained
Diego Alberto Tamayo
 
[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture
[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture
[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture
WSO2
 
Iota - Structure and Validation Method
Iota - Structure and Validation MethodIota - Structure and Validation Method
Iota - Structure and Validation Method
JY Chun
 
Supporting trade finance with letters of credit on corda
Supporting trade finance with letters of credit on cordaSupporting trade finance with letters of credit on corda
Supporting trade finance with letters of credit on corda
R3
 

Similar to Understanding Algorand's smart contract language (20)

Ethereum
EthereumEthereum
Ethereum
 
Ethereum Contracts - Coinfest 2015
Ethereum Contracts - Coinfest 2015Ethereum Contracts - Coinfest 2015
Ethereum Contracts - Coinfest 2015
 
Algorand August Release
Algorand August ReleaseAlgorand August Release
Algorand August Release
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
 
Ethereum
EthereumEthereum
Ethereum
 
Blockchain Programming
Blockchain ProgrammingBlockchain Programming
Blockchain Programming
 
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
 
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
 
Hello world contract
Hello world contractHello world contract
Hello world contract
 
Building Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart ContractBuilding Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart Contract
 
Smart Contracts with Solidity hands-on training session
Smart Contracts with Solidity hands-on training session  Smart Contracts with Solidity hands-on training session
Smart Contracts with Solidity hands-on training session
 
A living programming environment for a living blockchain
A living programming environment for a living blockchainA living programming environment for a living blockchain
A living programming environment for a living blockchain
 
A living programming environment for blockchain
A living programming environment for blockchainA living programming environment for blockchain
A living programming environment for blockchain
 
Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618
 
Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...
Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...
Flink Forward Berlin 2018: Shriya Arora - "Taming large-state to join dataset...
 
Corvil App Agent
Corvil App AgentCorvil App Agent
Corvil App Agent
 
1. ibm blockchain explained
1. ibm blockchain explained1. ibm blockchain explained
1. ibm blockchain explained
 
[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture
[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture
[WSO2Con USA 2018] Managing Transactions in Your Microservice Architecture
 
Iota - Structure and Validation Method
Iota - Structure and Validation MethodIota - Structure and Validation Method
Iota - Structure and Validation Method
 
Supporting trade finance with letters of credit on corda
Supporting trade finance with letters of credit on cordaSupporting trade finance with letters of credit on corda
Supporting trade finance with letters of credit on corda
 

More from Vanessa Lošić

Intro to DAOs
Intro to DAOsIntro to DAOs
Intro to DAOs
Vanessa Lošić
 
Hack DeFi Ideation
Hack DeFi IdeationHack DeFi Ideation
Hack DeFi Ideation
Vanessa Lošić
 
Encode Club Hackathon
Encode Club Hackathon  Encode Club Hackathon
Encode Club Hackathon
Vanessa Lošić
 
How fcm-works-v0.1 fc-club-22092021
How fcm-works-v0.1 fc-club-22092021How fcm-works-v0.1 fc-club-22092021
How fcm-works-v0.1 fc-club-22092021
Vanessa Lošić
 
Polkadot ideation
Polkadot ideationPolkadot ideation
Polkadot ideation
Vanessa Lošić
 
Encode polkadot club
Encode polkadot club  Encode polkadot club
Encode polkadot club
Vanessa Lošić
 
Textile
TextileTextile
Encode Club workshop slides
Encode Club workshop slidesEncode Club workshop slides
Encode Club workshop slides
Vanessa Lošić
 
Encode polkadot hack intro event
Encode polkadot hack intro eventEncode polkadot hack intro event
Encode polkadot hack intro event
Vanessa Lošić
 
Encode
EncodeEncode
Encode Club -_Pinning_Services_-_aug_2021
Encode Club -_Pinning_Services_-_aug_2021Encode Club -_Pinning_Services_-_aug_2021
Encode Club -_Pinning_Services_-_aug_2021
Vanessa Lošić
 
Encode Polkadot Club
Encode Polkadot Club   Encode Polkadot Club
Encode Polkadot Club
Vanessa Lošić
 
Interlay + Encode
Interlay + EncodeInterlay + Encode
Interlay + Encode
Vanessa Lošić
 
Subspace
SubspaceSubspace
Subspace
Vanessa Lošić
 
Intro to NFTs
Intro to NFTsIntro to NFTs
Intro to NFTs
Vanessa Lošić
 
Introduction to Filecoin
Introduction to Filecoin   Introduction to Filecoin
Introduction to Filecoin
Vanessa Lošić
 
Encode polkadot club event 3, technical deepdive
Encode polkadot club   event 3, technical deepdiveEncode polkadot club   event 3, technical deepdive
Encode polkadot club event 3, technical deepdive
Vanessa Lošić
 
Encode club introduction_to_libp2p
Encode club introduction_to_libp2pEncode club introduction_to_libp2p
Encode club introduction_to_libp2p
Vanessa Lošić
 
Encode polkadot club event 2, intro to polkadot
Encode polkadot club   event 2, intro to polkadotEncode polkadot club   event 2, intro to polkadot
Encode polkadot club event 2, intro to polkadot
Vanessa Lošić
 
Hack africa workshop_2_part_one_chilli_chelli
Hack africa workshop_2_part_one_chilli_chelliHack africa workshop_2_part_one_chilli_chelli
Hack africa workshop_2_part_one_chilli_chelli
Vanessa Lošić
 

More from Vanessa Lošić (20)

Intro to DAOs
Intro to DAOsIntro to DAOs
Intro to DAOs
 
Hack DeFi Ideation
Hack DeFi IdeationHack DeFi Ideation
Hack DeFi Ideation
 
Encode Club Hackathon
Encode Club Hackathon  Encode Club Hackathon
Encode Club Hackathon
 
How fcm-works-v0.1 fc-club-22092021
How fcm-works-v0.1 fc-club-22092021How fcm-works-v0.1 fc-club-22092021
How fcm-works-v0.1 fc-club-22092021
 
Polkadot ideation
Polkadot ideationPolkadot ideation
Polkadot ideation
 
Encode polkadot club
Encode polkadot club  Encode polkadot club
Encode polkadot club
 
Textile
TextileTextile
Textile
 
Encode Club workshop slides
Encode Club workshop slidesEncode Club workshop slides
Encode Club workshop slides
 
Encode polkadot hack intro event
Encode polkadot hack intro eventEncode polkadot hack intro event
Encode polkadot hack intro event
 
Encode
EncodeEncode
Encode
 
Encode Club -_Pinning_Services_-_aug_2021
Encode Club -_Pinning_Services_-_aug_2021Encode Club -_Pinning_Services_-_aug_2021
Encode Club -_Pinning_Services_-_aug_2021
 
Encode Polkadot Club
Encode Polkadot Club   Encode Polkadot Club
Encode Polkadot Club
 
Interlay + Encode
Interlay + EncodeInterlay + Encode
Interlay + Encode
 
Subspace
SubspaceSubspace
Subspace
 
Intro to NFTs
Intro to NFTsIntro to NFTs
Intro to NFTs
 
Introduction to Filecoin
Introduction to Filecoin   Introduction to Filecoin
Introduction to Filecoin
 
Encode polkadot club event 3, technical deepdive
Encode polkadot club   event 3, technical deepdiveEncode polkadot club   event 3, technical deepdive
Encode polkadot club event 3, technical deepdive
 
Encode club introduction_to_libp2p
Encode club introduction_to_libp2pEncode club introduction_to_libp2p
Encode club introduction_to_libp2p
 
Encode polkadot club event 2, intro to polkadot
Encode polkadot club   event 2, intro to polkadotEncode polkadot club   event 2, intro to polkadot
Encode polkadot club event 2, intro to polkadot
 
Hack africa workshop_2_part_one_chilli_chelli
Hack africa workshop_2_part_one_chilli_chelliHack africa workshop_2_part_one_chilli_chelli
Hack africa workshop_2_part_one_chilli_chelli
 

Recently uploaded

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 

Recently uploaded (20)

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 

Understanding Algorand's smart contract language

  • 2. ● Agenda ○ Overview of the types of smart contracts ■ Stateless Contracts ■ Stateful Contracts ■ Combining with other Algorand Technologies ○ Runtime Architecture ■ Stateless ■ Stateful ○ TEAL - Algorand Smart Contract Language ■ Opcodes and Examples ○ PyTeal and Reach Algorand Smart Contracts
  • 3. Algorand Smart Contracts - Layer 1 Smart Contract Contract or Escrow Delegation Application Stateless Stateful
  • 4. Escrow/Contract Account Stateless Smart Contract - Compiled Logic Becomes an Account Standard/Multisig Account Standard/Multisig Account Standard/Multisig Account Fund Account With Standard Transactions Assets/Algos Spend Transactions Gated by TEAL Program Standard/Multisig Account TEAL Logic
  • 5. Delegate Stateless Smart Contract - Logic Standard/Multisig Account Spend Transactions Gated by TEAL Program Standard/Multisig Account TEAL Logic Standard Transaction Sign Transaction Sign TEAL Logic Later Logic Signature
  • 6. Stateless Contract Usages • Contract Accounts • Escrows • HTLC • Split Payments • Limit Orders • Delegated • Recurring Payments • Limited Account Authority
  • 7. Stateful aka Apps Application Transaction Smart Contract Logic Global State Local State User 1 Local State User 1 Local State User 1 Local State User 1 Approval Program Clear Program Smart Contract Logic Deployed Stateful Contract Returns APPID Communicate with Application Transactions
  • 8. New Transaction Sub-Types for Application NoOp TEAL Logic Modify Local or Global state TEAL Logic Modify Local or Global state Approval Program Clear Program Optin DeleteApplication UpdateApplication CloseOut Clear Used to Communicate With Stateful Smart Contract Graceful Non-Graceful ie Will clear regardless
  • 9. Stateful Contract Usages • Defi Apps (AMM, lending, etc) • Crowdfunding • Voting • Material Tracking • Lottery • Seating • Identity Restrictions • Anywhere a global variable is needed • Anywhere a individual users values need to be manipulated
  • 10. Stateful vs Stateless Differences Stateful Stateless Evaluation Block Assembly Submission Size 1kb 1000 bytes Opcodes 700/Program 20000 Access to Ledger Facilitates Assets/Account Lookups Only Tx Based Values Track State Values Yes No Logic Lives on Chain Submitted with Tx(s) Templates Not Currently Yes (HTLC, Split, etc)
  • 12. CrowdFunding App Donation Operation Stateful Contract App Global State Fund Start Date Fund End Date Fund Goal Fund Amount Escrow Address Creator Address Receiver Address Fund Close Date Stateless Contract Escrow Holds All Donations Donate Transaction 2 - Payment Tx From Donator to Escrow Account Transaction 1 Stateful App Transaction Atomic Local Storage Giving Amount
  • 13. Voting App - Vote Operation Spend Vote Token Receive Vote Token From Commission Global State Registration Begin Round Registration End Round Vote Begin Round Vote End Round Candidate A Votes Candidate B Votes Vote Creator Stateful Contract App Transaction 2 - Asset Xfer From Voter to Commision Account Transaction 1 Stateful App Transaction Atomic Vote Commission
  • 15. Stack Runtime Stateless Runtime Architecture Global Vars Transaction(s) Properties Read Only Temporary Scratch Read/Write TEAL Program Arguments Per Transaction Transaction Submission
  • 16. Teal Stack Architecture (Stateless) #pragma version 3 txn Receiver addr SOEI... == && arg 0 len int 32 == && arg 0 sha256 byte base64 VeU... == && ... Program uint64/[]byte uint64/[]byte uint64/[]byte Stack …(up to 1000) 0: uint64/[]byte 1: uint64/[]byte 2: uint64/[]byte Scratch Space ... 255: uint64/[]byte 0: []byte 1: []byte 2: []byte Args (This txn only) …(up to 255) ● Sender ● Fee ● FirstValid ● FirstValidTime ● LastValid ● Note ● Lease ● Receiver ● Amount ● CloseRemainderTo ● VotePK ● SelectionPK ● VoteFirst ● VoteLast ● VoteKeyDilution ● Type ● TypeEnum ● XferAsset ● AssetAmount ● AssetSender ● AssetReceiver ● AssetCloseTo ● GroupIndex ● TxID Transaction(s)
  • 17. Stateful Contract Runtime Stateful Runtime Architecture Global Vars Transaction(s) Properties Read Only Stack TEAL Program(s), Loaded on Create Update Application Array - limit 2 Arguments Array Per Transaction Transaction Submission Accounts Array - limit 4 Temporary Scratch Read/Write Global/Local State Assets Array - limit 2
  • 18. Teal Stack Architecture (Stateful) #pragma version 3 byte "myarg" txn ApplicationArgs 0 == bz no_local int 0 byte "test" app_local_get pop no_local: // read global state byte "counter" app_global_get ... Program uint64/[]byte uint64/[]byte uint64/[]byte Stack …(up to 1000) 0: uint64/[]byte 1: uint64/[]byte 2: uint64/[]byte Scratch Space ... 255: uint64/[]byte Transaction(s) []byte []byte []byte Arguments* …(up to 16 & 2K) uint64 uint64 Applications* …(up to 2 app ids) []byte []byte Accounts* …(up to 4 accounts) Global State 64 K/V pairs 64 bytes Local State 16 K/V pairs 64 bytes * Can change per transaction ● Sender ● Fee ● FirstValid ● FirstValidTime ● LastValid ● Note ● Lease ● Receiver ● Amount ● CloseRemainderTo ● VotePK ● SelectionPK ● VoteFirst ● VoteLast ● VoteKeyDilution ● Type ● TypeEnum ● XferAsset ● AssetAmount ● AssetSender ● AssetReceiver ● AssetCloseTo ● GroupIndex ● TxID uint64 uint64 Assets* …(up to 2 asset ids)
  • 19. TEAL
  • 20. TEAL - Transaction Execution Approval Language ● Bytecode based stack language ● Returns True or False (One Positive Value Left on Stack) ● SDK Support ● > 80 Opcodes ● Access to ASA/Algo Balances ● Read all Transactions in a Group ● Stateful - Global/Local Storage Calls ● Stateless - Signature Verification ● PyTEAL library to write in python Push Pop
  • 21. Simple Stack Example txn Amount int 1000 >= Transaction Amount txn Amount int 1000 >= 1 1000 Transaction Amount txn Amount int 1000 >= 2 txn Amount int 1000 >= T r a n s a c t i o n A m o u n t 3 1 0 0 0 0/1 Transaction Amount >= 1000
  • 23. Pseudo Operators int //load an int onto stack byte //Load bytes on stack addr //Load Algorand address TEAL Approval Program txn Receiver addr HJLWACXDBOEH25KJB2WI2X5BHQOJ4LS2MRLNMHJ5ZZOBLJU7KGDJSHEU3I == . byte “mystring” txn ApplicationArgs 0 ==
  • 25. Branching Demo - b, bnz, bz
  • 26. Accessing Transaction Properties TEAL Approval Program txn Amount int 1000 >= ● Sender ● Fee ● FirstValid ● FirstValidTime ● LastValid ● Note ● Lease ● Receiver ● Amount ● CloseRemainderTo ● VotePK ● SelectionPK ● VoteFirst ● VoteLast ● VoteKeyDilution ● Type ● TypeEnum ● XferAsset ● AssetAmount ● AssetSender ● AssetReceiver ● AssetCloseTo ● GroupIndex ● TxID
  • 28. Checking Type of Transaction TEAL Approval Program txn TypeEnum int appl ==
  • 29. Application Transaction Sub-Types - Stateful TEAL Approval Program txn OnCompletion int NoOp ==
  • 30. Atomic Transactions - gtxn vs txn Transaction 1 Call to Stateful Contract Transaction 2 Payment Transaction Transaction 3 Asset Transfer Transaction Atomic TEAL Approval Program global GroupSize int 3 == gtxn 0 TypeEnum int appl == && gtxn 1 TypeEnum Int pay == && gtxn 2 TypeEnum axfer == &&
  • 32. Asset Check TEAL Approval Program int 0 //Sender of tx int 2 //asset id asset_holding_get AssetBalance pop //assume they have the asset int 1 >= Transaction 1 Call to Stateful Contract
  • 33. Read Global State From Another Contract Readonly
  • 34. Read Other Contracts State Demo
  • 35. Reading and Writing Local State int 0 //sender byte "MyAmountGiven" txn Amount app_local_put int 0 //sender byte "MyAmountGiven" app_local_get int 1 //Account 1 int 1234 //other contract id byte “OtherContractKey” app_local_get_ex Account 1 Account 2 Accounts Transaction 1 Call to Stateful Contract Account 3 Account 4 Sender Local State 16 K/V pairs 64 bytes Account 1 Local State 16 K/V pairs 64 bytes Local State 16 K/V pairs 64 bytes Account 4 Read/Write Read Only Account 4 Local State 16 K/V pairs 64 bytes for Different Contract Local State 16 K/V pairs 64 bytes for Different Contract Sender
  • 38. Smart Contract Options TEAL PyTeal Compiler Reach Application Business Logic TEAL TEAL TEAL TEAL
  • 39. def bank_for_account(receiver): is_payment = Txn.type_enum() == TxnType.Payment is_single_tx = Global.group_size() == Int(1) is_correct_receiver = Txn.receiver() == Addr(receiver) return And( is_payment, is_single_tx, is_correct_receiver ) if __name__ == "__main__": program = bank_for_account("ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFL XXD3PFSNJJBYAFZM") print(compileTeal(program, Mode.Signature)) PyTEAL -Python Library Returns #pragma version 2 txn TypeEnum int pay == global GroupSize int 1 == && txn Receiver addr ZZAF5ARA4MEC5PVDOP64JM5O5MQST63Q2KOY2FLYFLXXD3P FSNJJBYAFZM == &&
  • 43. Follow Guidelines for Safety Boilerplate Approval Program Example Stateless Contract Adhere to These Guidelines to Protect Accounts Size Limitations and Opcode Cost Limits
  • 45. Resources ● Discord: https://discord.gg/YgPTCVk ● Developer Portal (Documentation and Tutorials): https://developer.algorand.org/ ● Forum: https://forum.algorand.org/ ● GitHub: https://github.com/algorand ● OFFICE HOURS sign up: https://www.algorand.com/developers