SlideShare a Scribd company logo
Algorand Smart Contracts
Jason Weathersby, Sr Director Developer Relations,
Algorand
@JasonWeathersby
Agenda
• Overview of Smart Contracts
• Transaction Execution Approval Language (TEAL)
• Developing Smart Contracts with Python
Mobile/Web Off Chain
App
Algorand Dapp Architecture
Algorand Blockchain
Algorand SDKs
Smart
Contract
Smart
Contract
Smart
Contract
T
T
T
Transactions
Mobile App
WalletConnect
AlgoSigner SDK
MyAlgo SDK
Sign
Chrome Plugin
JavaScript Lib
Others
Wallet
What is a Smart Contract
Smart
Contract
In Development
Smart
Contract
Smart
Contract
Smart
Contract
Ledger
Algorand Blockchain
Deploy
● Small Piece of Logic that lives on the chain
● Initiated by a transaction
● Returns True or False-Approve/Fail TX
● Can be grouped with other Transactions
● Written in TEAL or PyTeal or Generated By
Reach Framework
Smart Contract High Level
Smart
Contract
Smart
Contract
Smart
Contract
Ledger
Algorand Blockchain
Application Transaction
Contract Logic
and data read
from Ledger
determine pass
or fail
Contract can
write global/local
values to the
ledger
Contract can
also initiate new
transactions
Smart Contracts aka Apps
Application Transaction
TEAL
Global State
Local State User 1
Local State User 1
Local State User 1
Local State User 1
Approval Program
Clear Program
TEAL
AVM
Communicate with Application
Transactions
Transaction Sub-Types for Application
NoOp TEAL Logic
TEAL Logic
Approval Program
Clear Program
Optin
DeleteApplication
UpdateApplication
CloseOut
Clear
Used to Communicate With Smart Contract
Graceful
Non-Graceful
ie Will clear
regardless
Smart Contracts as Escrows
Smart Contract Escrow
Application Transaction Smart
Contract
AVM
Deploy
Algorand Address and
Unique ID
T
T
T
Smart Contract Escrow
Application Transaction Smart
Contract
Global State
Local State User 1
Local State User 1
Local State User 1
Local State User 1
AVM
Inner Transactions (Up To 256):
● Payment Transactions
● Create and/or Transfer ASAs
● Freeze or Clawback ASAs
● Opt into another ASA
● Application Call
T
T
T
Smart Contract to Smart Contract Calling
Contract A
Process B Return
using itxn logs
Contract B
Process C Return
using itxn logs
Contract C
Application
Transaction
Inner
Transaction
Inner
Transaction
Returns Returns
Level 1 Level 2 Level 3 Level 8
Runtime Architecture
Smart Contract Runtime
Smart Contract Runtime Architecture
Global Vars
Transaction(s)
Properties
Read Only
Stack
TEAL
Program(s),
Loaded on
Create
Update
Temporary
Scratch
Read/Write
Global/Local
State K/V
pairs
Up to 256 Inner
Transactions
Application
Transaction
Accounts
Applications
Assets
Arguments
Restrict View
of Ledger
Quick Glance At ABI
Application Binary Interface (ABI)
• Standard for Describing Methods, Interfaces and Contracts
• Described in JSON
• SDKs read and convert to proper smart contract calls, parameters and return types
https://developer.algorand.org/articles/contract-to-contract-calls-and-an-abi-come-to-algorand/
https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md
"add(uint64)uint64"
Method Signature
https://www.youtube.com/watch?v=ajAAy9d3B_0
Transaction Execution Appoval
Language (TEAL)
TEAL - Transaction Execution Approval
Language
● Bytecode based stack language
● Turing Complete
● Looping and Subroutines
● Only Uint64 and Byte[] allowed on stack
● True or False - Positive value on stack
● > 140 Opcodes
● PyTeal library to write in python
&&
arg 0
len
…
Push
Pop
Simple Stack Example
txn Amount
int 1000
>=
Transaction Amount
txn Amount
int 1000
>=
1
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
Transaction Amount >= 1000
1000
Transaction Amount
0/1
Push
Push
Pop
Push
Opcodes
Opcode Reference Document
Simple Addition TEAL Demo
PyTeal
PyTeal
• Python Library that produces TEAL
• TEAL compiled to bytecode and
runs on Algorand AVM
• Contracts are created as PyTeal
Expression Trees
PyTeal Code
TEAL Source
Compile To TEAL
Create with Python
Compile with PyTeal
https://pyteal.readthedocs.io/en/stable/index.html
PyTeal to Teal
TEAL
Approval Program
Clear Program
TEAL
Smart Contract
PyTeal
Expression
Tree
PyTeal
Expression
Tree
Python Source File
PyTeal Expressions
● PyTeal Object that compiles to TEAL
● Expressions are created using PyTeal Class methods
● Expression Trees are just a collection of connected Expressions
Python Variable PyTEAL Expression
PyTeal Method to
Produce Teal from
Expression Tree
Leaf
Expression
Root
Expression
Leaf
Expression
Expressions that take parameters Must Be Passed other Expressions as
parameters
PyTeal Expression Tree Example
Transaction Amount >= 10000 and <= 20000
Expression 1: Txn.amount()
Expression 2: Int(10000)
Expression 3
Ge(exp1, exp2)
>=
Expression 1: Txn.amount()
Expression 4: Int(20000)
Expression 5
Le(exp1, exp4)
<=
Expression 6
And(exp3, exp5)
&&
And(Txn.amount() >= Int(10000), Txn.amount() <= Int(20000))
PyTeal Expression Tree Control Flow
ExpressionTree1
Condition 1
ExpressionTree2
Condition 2
FinalExpression
return Cond(
[Int(1) == Int(0), tree1],
[Int(1) == Int(1), tree2],
)
PyTeal Example
0
1
2
Application Transaction
ABI Method sub(1)
Application Transaction
ABI Method add(1)
Incrementing Counter
Smart
Contract
Appt
Algorand Blockchain
Global
Counter
Transaction Properties
https://pyteal.readthedocs.io/en/stable/accessing_transaction_field.html#id1
Gtxn[0].sender() #tran group size 0 based
Global.group_size() #get size of group
Transaction Routing
First Success Breaks Out Of Cond()
All Expressions for body must eval to
same Teal Type
Create and Initialize the Global counter to 0
https://pyteal.readthedocs.io/en/stable/control_structures.html#chaining-expressions-seq
https://pyteal.readthedocs.io/en/stable/state.html#writing-global-state
All Expressions But The Last Must
Resolve to Teal Type of None
Not Allowed
Seq( Int(1), Int(1) )
Only byte[] or uint64 Allowed
Application Call Arrays
Smart Contract
Application
Application
Transaction
Accounts
Applications
Assets
Arguments
Accounts[0] is Always Sender
Applications[0] is Always Current App
Arguments[0] Contains Meth Sig for
ABI Calls
Switch on Specific ABI Method - call add or
sub
https://pyteal.readthedocs.io/en/stable/accessing_transaction_field.html?#transaction-array-fields
https://pyteal.readthedocs.io/en/stable/arithmetic_expression.html
PyTeal Overloads Python Operators
Implement Add and Deduct
https://pyteal.readthedocs.io/en/stable/control_structures.html#simple-branching-if
Do not let the Counter go below 0
https://pyteal.readthedocs.io/en/stable/state.html#reading-global-state
If( test-expr, then-expr, else-expr )
Add Function
ABI Return
Marker
ABI Concat
Return
Marker With
Updated
Value
Deduct Function
Handle
Negative
Number
Check
Compile the Smart Contract
Call the Smart Contract
Call the Smart Contract from Python
https://developer.algorand.org/docs/get-details/atc/
Smart Contract Execution
Link To Presentation
•
Resources
● Discord: https://discord.com/invite/84AActu3at
● 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

DeFi - What it's all about
DeFi - What it's all aboutDeFi - What it's all about
DeFi - What it's all about
Chinmay Patel
 
Tokenomics - Blockchain & Cryptocurrency Tokenomics
Tokenomics - Blockchain & Cryptocurrency TokenomicsTokenomics - Blockchain & Cryptocurrency Tokenomics
Tokenomics - Blockchain & Cryptocurrency Tokenomics
Codezeros
 
Decentralized bank-Aave: presented by Outliers
Decentralized bank-Aave: presented by OutliersDecentralized bank-Aave: presented by Outliers
Decentralized bank-Aave: presented by Outliers
LuyaoZhangPhD
 
NFT Marketplace: Your Complete Guide For 2022
NFT Marketplace: Your Complete Guide For 2022 NFT Marketplace: Your Complete Guide For 2022
NFT Marketplace: Your Complete Guide For 2022
ForceBolt
 
Consensus Algorithms.pptx
Consensus Algorithms.pptxConsensus Algorithms.pptx
Consensus Algorithms.pptx
Rajapriya82
 
Tokenomics Overview
Tokenomics OverviewTokenomics Overview
Tokenomics Overview
Reyan Lamrani
 
Top 5 DeFi Applications
Top 5 DeFi ApplicationsTop 5 DeFi Applications
Top 5 DeFi Applications
101 Blockchains
 
Blockchain consensus algorithms
Blockchain consensus algorithmsBlockchain consensus algorithms
Blockchain consensus algorithms
Anurag Dashputre
 
Blockchain ppt
Blockchain pptBlockchain ppt
Blockchain ppt
abhi sharma
 
Algorand blockchain basics, decentralized and for developers
Algorand blockchain basics, decentralized and for developersAlgorand blockchain basics, decentralized and for developers
Algorand blockchain basics, decentralized and for developers
Russ Fustino
 
Week 3 - Cryptocurrencies
Week 3 - CryptocurrenciesWeek 3 - Cryptocurrencies
Week 3 - Cryptocurrencies
Roger Royse
 
Understanding Blockchain: Distributed Ledger Technology
Understanding Blockchain: Distributed Ledger TechnologyUnderstanding Blockchain: Distributed Ledger Technology
Understanding Blockchain: Distributed Ledger Technology
Suraj Kumar Jana
 
Bitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & BlockchainBitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & Blockchain
Jitendra Chittoda
 
Bitcoin, Cryptocurrency, & Blockchain Presentation
Bitcoin, Cryptocurrency, & Blockchain PresentationBitcoin, Cryptocurrency, & Blockchain Presentation
Bitcoin, Cryptocurrency, & Blockchain Presentation
MaxWheelock
 
Election System Based on Blockchain Technology
Election System Based on Blockchain TechnologyElection System Based on Blockchain Technology
Election System Based on Blockchain Technology
AIRCC Publishing Corporation
 
BITCOIN EXPLAINED
BITCOIN EXPLAINEDBITCOIN EXPLAINED
BITCOIN EXPLAINED
Murlidhar Sarda
 
WALLET PARA CRIPTOMONEDAS
WALLET PARA CRIPTOMONEDASWALLET PARA CRIPTOMONEDAS
WALLET PARA CRIPTOMONEDAS
EnmerLR
 
Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)
Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)
Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)
Svetlin Nakov
 
Blockchain and DeFi: Overview
Blockchain and DeFi: OverviewBlockchain and DeFi: Overview
Blockchain and DeFi: Overview
Svetlin Nakov
 
Introduction To Solidity
Introduction To SolidityIntroduction To Solidity
Introduction To Solidity
101 Blockchains
 

What's hot (20)

DeFi - What it's all about
DeFi - What it's all aboutDeFi - What it's all about
DeFi - What it's all about
 
Tokenomics - Blockchain & Cryptocurrency Tokenomics
Tokenomics - Blockchain & Cryptocurrency TokenomicsTokenomics - Blockchain & Cryptocurrency Tokenomics
Tokenomics - Blockchain & Cryptocurrency Tokenomics
 
Decentralized bank-Aave: presented by Outliers
Decentralized bank-Aave: presented by OutliersDecentralized bank-Aave: presented by Outliers
Decentralized bank-Aave: presented by Outliers
 
NFT Marketplace: Your Complete Guide For 2022
NFT Marketplace: Your Complete Guide For 2022 NFT Marketplace: Your Complete Guide For 2022
NFT Marketplace: Your Complete Guide For 2022
 
Consensus Algorithms.pptx
Consensus Algorithms.pptxConsensus Algorithms.pptx
Consensus Algorithms.pptx
 
Tokenomics Overview
Tokenomics OverviewTokenomics Overview
Tokenomics Overview
 
Top 5 DeFi Applications
Top 5 DeFi ApplicationsTop 5 DeFi Applications
Top 5 DeFi Applications
 
Blockchain consensus algorithms
Blockchain consensus algorithmsBlockchain consensus algorithms
Blockchain consensus algorithms
 
Blockchain ppt
Blockchain pptBlockchain ppt
Blockchain ppt
 
Algorand blockchain basics, decentralized and for developers
Algorand blockchain basics, decentralized and for developersAlgorand blockchain basics, decentralized and for developers
Algorand blockchain basics, decentralized and for developers
 
Week 3 - Cryptocurrencies
Week 3 - CryptocurrenciesWeek 3 - Cryptocurrencies
Week 3 - Cryptocurrencies
 
Understanding Blockchain: Distributed Ledger Technology
Understanding Blockchain: Distributed Ledger TechnologyUnderstanding Blockchain: Distributed Ledger Technology
Understanding Blockchain: Distributed Ledger Technology
 
Bitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & BlockchainBitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & Blockchain
 
Bitcoin, Cryptocurrency, & Blockchain Presentation
Bitcoin, Cryptocurrency, & Blockchain PresentationBitcoin, Cryptocurrency, & Blockchain Presentation
Bitcoin, Cryptocurrency, & Blockchain Presentation
 
Election System Based on Blockchain Technology
Election System Based on Blockchain TechnologyElection System Based on Blockchain Technology
Election System Based on Blockchain Technology
 
BITCOIN EXPLAINED
BITCOIN EXPLAINEDBITCOIN EXPLAINED
BITCOIN EXPLAINED
 
WALLET PARA CRIPTOMONEDAS
WALLET PARA CRIPTOMONEDASWALLET PARA CRIPTOMONEDAS
WALLET PARA CRIPTOMONEDAS
 
Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)
Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)
Consensus Algorithms - Nakov at CryptoBlockCon - Las Vegas (2018)
 
Blockchain and DeFi: Overview
Blockchain and DeFi: OverviewBlockchain and DeFi: Overview
Blockchain and DeFi: Overview
 
Introduction To Solidity
Introduction To SolidityIntroduction To Solidity
Introduction To Solidity
 

Similar to Algorand Smart Contracts

Understanding Algorand's smart contract language
Understanding Algorand's smart contract language   Understanding Algorand's smart contract language
Understanding Algorand's smart contract language
Vanessa Lošić
 
Algorand Educate: Intro to Algorand
Algorand Educate: Intro to AlgorandAlgorand Educate: Intro to Algorand
Algorand Educate: Intro to Algorand
TinaBregovi
 
Hyperledger Fabric & Composer
Hyperledger Fabric & Composer Hyperledger Fabric & Composer
Hyperledger Fabric & Composer
Dr. Ketan Parmar
 
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
 
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
 
How to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contractHow to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contract
Joseph Holbrook, Chief Learning Officer (CLO)
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
عطاءالمنعم اثیل شیخ
 
Fluence.sh
Fluence.sh Fluence.sh
Fluence.sh
Fluence.sh
 
What you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondWhat you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyond
Jon Galloway
 
Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008
SteveMillidge
 
Interledger DvP Settlement on Amazon Managed Blockchain
Interledger DvP Settlement on Amazon Managed BlockchainInterledger DvP Settlement on Amazon Managed Blockchain
Interledger DvP Settlement on Amazon Managed Blockchain
Amazon Web Services
 
Introduction of Hyperledger Fabric & Composer
Introduction of Hyperledger Fabric & Composer Introduction of Hyperledger Fabric & Composer
Introduction of Hyperledger Fabric & Composer
Dr. Ketan Parmar
 
Hello world contract
Hello world contractHello world contract
Hello world contract
Gene Leybzon
 
Parity Progress Report
Parity Progress ReportParity Progress Report
Parity Progress Report
gavofyork
 
Ethereum
EthereumEthereum
Ethereum
Brian Yap
 
Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618
Arnaud Le Hors
 
How to be a smart contract engineer
How to be a smart contract engineerHow to be a smart contract engineer
How to be a smart contract engineer
Oded Noam
 
Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...
Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...
Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...
AFAS Software
 
How to Build a Decentralized Blockchain App with the Oracle Blockchain Platform
How to Build a Decentralized BlockchainApp with the Oracle Blockchain PlatformHow to Build a Decentralized BlockchainApp with the Oracle Blockchain Platform
How to Build a Decentralized Blockchain App with the Oracle Blockchain Platform
Juarez Junior
 
How to build a dApp in StarkNet
How to build a dApp in StarkNetHow to build a dApp in StarkNet
How to build a dApp in StarkNet
TinaBregovi
 

Similar to Algorand Smart Contracts (20)

Understanding Algorand's smart contract language
Understanding Algorand's smart contract language   Understanding Algorand's smart contract language
Understanding Algorand's smart contract language
 
Algorand Educate: Intro to Algorand
Algorand Educate: Intro to AlgorandAlgorand Educate: Intro to Algorand
Algorand Educate: Intro to Algorand
 
Hyperledger Fabric & Composer
Hyperledger Fabric & Composer Hyperledger Fabric & Composer
Hyperledger Fabric & Composer
 
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
 
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
 
How to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contractHow to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contract
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
 
Fluence.sh
Fluence.sh Fluence.sh
Fluence.sh
 
What you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondWhat you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyond
 
Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008
 
Interledger DvP Settlement on Amazon Managed Blockchain
Interledger DvP Settlement on Amazon Managed BlockchainInterledger DvP Settlement on Amazon Managed Blockchain
Interledger DvP Settlement on Amazon Managed Blockchain
 
Introduction of Hyperledger Fabric & Composer
Introduction of Hyperledger Fabric & Composer Introduction of Hyperledger Fabric & Composer
Introduction of Hyperledger Fabric & Composer
 
Hello world contract
Hello world contractHello world contract
Hello world contract
 
Parity Progress Report
Parity Progress ReportParity Progress Report
Parity Progress Report
 
Ethereum
EthereumEthereum
Ethereum
 
Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618
 
How to be a smart contract engineer
How to be a smart contract engineerHow to be a smart contract engineer
How to be a smart contract engineer
 
Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...
Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...
Michiel Overeem (AFAS) - Enterprise software schaalbaar maken met Service Fab...
 
How to Build a Decentralized Blockchain App with the Oracle Blockchain Platform
How to Build a Decentralized BlockchainApp with the Oracle Blockchain PlatformHow to Build a Decentralized BlockchainApp with the Oracle Blockchain Platform
How to Build a Decentralized Blockchain App with the Oracle Blockchain Platform
 
How to build a dApp in StarkNet
How to build a dApp in StarkNetHow to build a dApp in StarkNet
How to build a dApp in StarkNet
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 

Algorand Smart Contracts

  • 1. Algorand Smart Contracts Jason Weathersby, Sr Director Developer Relations, Algorand @JasonWeathersby
  • 2. Agenda • Overview of Smart Contracts • Transaction Execution Approval Language (TEAL) • Developing Smart Contracts with Python
  • 3. Mobile/Web Off Chain App Algorand Dapp Architecture Algorand Blockchain Algorand SDKs Smart Contract Smart Contract Smart Contract T T T Transactions Mobile App WalletConnect AlgoSigner SDK MyAlgo SDK Sign Chrome Plugin JavaScript Lib Others Wallet
  • 4. What is a Smart Contract Smart Contract In Development Smart Contract Smart Contract Smart Contract Ledger Algorand Blockchain Deploy ● Small Piece of Logic that lives on the chain ● Initiated by a transaction ● Returns True or False-Approve/Fail TX ● Can be grouped with other Transactions ● Written in TEAL or PyTeal or Generated By Reach Framework
  • 5. Smart Contract High Level Smart Contract Smart Contract Smart Contract Ledger Algorand Blockchain Application Transaction Contract Logic and data read from Ledger determine pass or fail Contract can write global/local values to the ledger Contract can also initiate new transactions
  • 6. Smart Contracts aka Apps Application Transaction TEAL Global State Local State User 1 Local State User 1 Local State User 1 Local State User 1 Approval Program Clear Program TEAL AVM Communicate with Application Transactions
  • 7. Transaction Sub-Types for Application NoOp TEAL Logic TEAL Logic Approval Program Clear Program Optin DeleteApplication UpdateApplication CloseOut Clear Used to Communicate With Smart Contract Graceful Non-Graceful ie Will clear regardless
  • 9. Smart Contract Escrow Application Transaction Smart Contract AVM Deploy Algorand Address and Unique ID T T T
  • 10. Smart Contract Escrow Application Transaction Smart Contract Global State Local State User 1 Local State User 1 Local State User 1 Local State User 1 AVM Inner Transactions (Up To 256): ● Payment Transactions ● Create and/or Transfer ASAs ● Freeze or Clawback ASAs ● Opt into another ASA ● Application Call T T T
  • 11. Smart Contract to Smart Contract Calling Contract A Process B Return using itxn logs Contract B Process C Return using itxn logs Contract C Application Transaction Inner Transaction Inner Transaction Returns Returns Level 1 Level 2 Level 3 Level 8
  • 13. Smart Contract Runtime Smart Contract Runtime Architecture Global Vars Transaction(s) Properties Read Only Stack TEAL Program(s), Loaded on Create Update Temporary Scratch Read/Write Global/Local State K/V pairs Up to 256 Inner Transactions Application Transaction Accounts Applications Assets Arguments Restrict View of Ledger
  • 15. Application Binary Interface (ABI) • Standard for Describing Methods, Interfaces and Contracts • Described in JSON • SDKs read and convert to proper smart contract calls, parameters and return types https://developer.algorand.org/articles/contract-to-contract-calls-and-an-abi-come-to-algorand/ https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md "add(uint64)uint64" Method Signature https://www.youtube.com/watch?v=ajAAy9d3B_0
  • 17. TEAL - Transaction Execution Approval Language ● Bytecode based stack language ● Turing Complete ● Looping and Subroutines ● Only Uint64 and Byte[] allowed on stack ● True or False - Positive value on stack ● > 140 Opcodes ● PyTeal library to write in python && arg 0 len … Push Pop
  • 18. Simple Stack Example txn Amount int 1000 >= Transaction Amount txn Amount int 1000 >= 1 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 Transaction Amount >= 1000 1000 Transaction Amount 0/1 Push Push Pop Push
  • 22. PyTeal • Python Library that produces TEAL • TEAL compiled to bytecode and runs on Algorand AVM • Contracts are created as PyTeal Expression Trees PyTeal Code TEAL Source Compile To TEAL Create with Python Compile with PyTeal https://pyteal.readthedocs.io/en/stable/index.html
  • 23. PyTeal to Teal TEAL Approval Program Clear Program TEAL Smart Contract PyTeal Expression Tree PyTeal Expression Tree Python Source File
  • 24. PyTeal Expressions ● PyTeal Object that compiles to TEAL ● Expressions are created using PyTeal Class methods ● Expression Trees are just a collection of connected Expressions Python Variable PyTEAL Expression PyTeal Method to Produce Teal from Expression Tree Leaf Expression Root Expression Leaf Expression Expressions that take parameters Must Be Passed other Expressions as parameters
  • 25. PyTeal Expression Tree Example Transaction Amount >= 10000 and <= 20000 Expression 1: Txn.amount() Expression 2: Int(10000) Expression 3 Ge(exp1, exp2) >= Expression 1: Txn.amount() Expression 4: Int(20000) Expression 5 Le(exp1, exp4) <= Expression 6 And(exp3, exp5) && And(Txn.amount() >= Int(10000), Txn.amount() <= Int(20000))
  • 26. PyTeal Expression Tree Control Flow ExpressionTree1 Condition 1 ExpressionTree2 Condition 2 FinalExpression return Cond( [Int(1) == Int(0), tree1], [Int(1) == Int(1), tree2], )
  • 28. 0 1 2 Application Transaction ABI Method sub(1) Application Transaction ABI Method add(1) Incrementing Counter Smart Contract Appt Algorand Blockchain Global Counter
  • 30. Transaction Routing First Success Breaks Out Of Cond() All Expressions for body must eval to same Teal Type
  • 31. Create and Initialize the Global counter to 0 https://pyteal.readthedocs.io/en/stable/control_structures.html#chaining-expressions-seq https://pyteal.readthedocs.io/en/stable/state.html#writing-global-state All Expressions But The Last Must Resolve to Teal Type of None Not Allowed Seq( Int(1), Int(1) ) Only byte[] or uint64 Allowed
  • 32. Application Call Arrays Smart Contract Application Application Transaction Accounts Applications Assets Arguments Accounts[0] is Always Sender Applications[0] is Always Current App Arguments[0] Contains Meth Sig for ABI Calls
  • 33. Switch on Specific ABI Method - call add or sub https://pyteal.readthedocs.io/en/stable/accessing_transaction_field.html?#transaction-array-fields https://pyteal.readthedocs.io/en/stable/arithmetic_expression.html PyTeal Overloads Python Operators
  • 34. Implement Add and Deduct https://pyteal.readthedocs.io/en/stable/control_structures.html#simple-branching-if Do not let the Counter go below 0 https://pyteal.readthedocs.io/en/stable/state.html#reading-global-state If( test-expr, then-expr, else-expr )
  • 35. Add Function ABI Return Marker ABI Concat Return Marker With Updated Value
  • 37. Compile the Smart Contract
  • 38. Call the Smart Contract
  • 39. Call the Smart Contract from Python https://developer.algorand.org/docs/get-details/atc/
  • 42. Resources ● Discord: https://discord.com/invite/84AActu3at ● 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