SlideShare a Scribd company logo
1 of 42
Download to read offline
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

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 developersRuss Fustino
 
Blockchain Technology Fundamentals
Blockchain Technology FundamentalsBlockchain Technology Fundamentals
Blockchain Technology FundamentalsExperfy
 
Blockchain Intro to Hyperledger Fabric
Blockchain Intro to Hyperledger Fabric Blockchain Intro to Hyperledger Fabric
Blockchain Intro to Hyperledger Fabric Araf Karsh Hamid
 
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ć
 
►TOP 13 • Blockchain Use Cases
►TOP 13 • Blockchain Use Cases ►TOP 13 • Blockchain Use Cases
►TOP 13 • Blockchain Use Cases Andrea Soto
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to BlockchainMalak Abu Hammad
 
Blockchain Fundamentals - Top Rated for Beginners
Blockchain Fundamentals - Top Rated for Beginners Blockchain Fundamentals - Top Rated for Beginners
Blockchain Fundamentals - Top Rated for Beginners 101 Blockchains
 
Write smart contract with solidity on Ethereum
Write smart contract with solidity on EthereumWrite smart contract with solidity on Ethereum
Write smart contract with solidity on EthereumMurughan Palaniachari
 
Examples of Smart Contracts
Examples of Smart ContractsExamples of Smart Contracts
Examples of Smart Contracts101 Blockchains
 
Blockchain, working [blockchain vs bitcoin] pros and cons
Blockchain, working [blockchain vs bitcoin] pros and consBlockchain, working [blockchain vs bitcoin] pros and cons
Blockchain, working [blockchain vs bitcoin] pros and consJerin Sebastian
 
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsTechracers
 
Basic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgersBasic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgersKoen Vingerhoets
 
Overview of Blockchain Consensus Mechanisms
Overview of Blockchain Consensus MechanismsOverview of Blockchain Consensus Mechanisms
Overview of Blockchain Consensus MechanismsJohannes Ahlmann
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to BlockchainJordan Harris
 
Blockchain in Banking, Business and Beyond
Blockchain in Banking, Business and BeyondBlockchain in Banking, Business and Beyond
Blockchain in Banking, Business and BeyondMichael Novak
 

What's hot (20)

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
 
Blockchain Technology Fundamentals
Blockchain Technology FundamentalsBlockchain Technology Fundamentals
Blockchain Technology Fundamentals
 
Blockchain Intro to Hyperledger Fabric
Blockchain Intro to Hyperledger Fabric Blockchain Intro to Hyperledger Fabric
Blockchain Intro to Hyperledger Fabric
 
Algorand
AlgorandAlgorand
Algorand
 
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
AlgorandAlgorand
Algorand
 
►TOP 13 • Blockchain Use Cases
►TOP 13 • Blockchain Use Cases ►TOP 13 • Blockchain Use Cases
►TOP 13 • Blockchain Use Cases
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchain
 
Smart contracts
Smart contractsSmart contracts
Smart contracts
 
Blockchain Fundamentals - Top Rated for Beginners
Blockchain Fundamentals - Top Rated for Beginners Blockchain Fundamentals - Top Rated for Beginners
Blockchain Fundamentals - Top Rated for Beginners
 
Write smart contract with solidity on Ethereum
Write smart contract with solidity on EthereumWrite smart contract with solidity on Ethereum
Write smart contract with solidity on Ethereum
 
Examples of Smart Contracts
Examples of Smart ContractsExamples of Smart Contracts
Examples of Smart Contracts
 
Blockchain, working [blockchain vs bitcoin] pros and cons
Blockchain, working [blockchain vs bitcoin] pros and consBlockchain, working [blockchain vs bitcoin] pros and cons
Blockchain, working [blockchain vs bitcoin] pros and cons
 
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart Contracts
 
Basic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgersBasic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgers
 
Overview of Blockchain Consensus Mechanisms
Overview of Blockchain Consensus MechanismsOverview of Blockchain Consensus Mechanisms
Overview of Blockchain Consensus Mechanisms
 
Smart contract
Smart contractSmart contract
Smart contract
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchain
 
Hyperledger
HyperledgerHyperledger
Hyperledger
 
Blockchain in Banking, Business and Beyond
Blockchain in Banking, Business and BeyondBlockchain in Banking, Business and Beyond
Blockchain in Banking, Business and Beyond
 

Similar to Algorand Smart Contracts

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 101Simone 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
 
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 beyondJon Galloway
 
Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008Portlets 2.0 Tssjs Prague 2008
Portlets 2.0 Tssjs Prague 2008SteveMillidge
 
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 BlockchainAmazon 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 contractGene Leybzon
 
Parity Progress Report
Parity Progress ReportParity Progress Report
Parity Progress Reportgavofyork
 
Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618Hyperledger Fabric Application Development 20190618
Hyperledger Fabric Application Development 20190618Arnaud 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 engineerOded 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 PlatformJuarez 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 StarkNetTinaBregovi
 
Blockchain technology-in-fin tech - Anton Sitnikov
Blockchain technology-in-fin tech - Anton SitnikovBlockchain technology-in-fin tech - Anton Sitnikov
Blockchain technology-in-fin tech - Anton SitnikovDataFest Tbilisi
 
Presentation_Topalidis_Giorgos
Presentation_Topalidis_GiorgosPresentation_Topalidis_Giorgos
Presentation_Topalidis_GiorgosGiorgos Topalidis
 

Similar to Algorand Smart Contracts (20)

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
 
Blockchain technology-in-fin tech - Anton Sitnikov
Blockchain technology-in-fin tech - Anton SitnikovBlockchain technology-in-fin tech - Anton Sitnikov
Blockchain technology-in-fin tech - Anton Sitnikov
 
Presentation_Topalidis_Giorgos
Presentation_Topalidis_GiorgosPresentation_Topalidis_Giorgos
Presentation_Topalidis_Giorgos
 

Recently uploaded

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 

Recently uploaded (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 

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