Skip to content

Commit

Permalink
doc: add hello world examples
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx committed Dec 11, 2023
1 parent d6a29b6 commit 7cb1339
Show file tree
Hide file tree
Showing 37 changed files with 1,117 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/hello_world/arc4_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from puyapy import ARC4Contract, Bytes, log
from puyapy.arc4 import String, abimethod


class HelloWorldContract(ARC4Contract):
@abimethod
def say_hello(self, name: String) -> None:
log(Bytes(b"Hello ") + name.decode())
11 changes: 11 additions & 0 deletions examples/hello_world/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from puyapy import Bytes, Contract, Transaction, log


class HelloWorldContract(Contract):
def approval_program(self) -> bool:
name = Transaction.application_args(0)
log(Bytes(b"Hello ") + name)
return True

def clear_state_program(self) -> bool:
return True
54 changes: 54 additions & 0 deletions examples/hello_world/out/application.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"hints": {
"say_hello(string)void": {
"call_config": {
"no_op": "CALL"
}
}
},
"source": {
"approval": "I3ByYWdtYSB2ZXJzaW9uIDgKCi8vIGV4YW1wbGVzLmhlbGxvX3dvcmxkLmFyYzRfY29udHJhY3QuSGVsbG9Xb3JsZENvbnRyYWN0LmFwcHJvdmFsX3Byb2dyYW0oKSAtPiB1aW50NjQ6Cm1haW5fYmxvY2tAMDoKICAgICAgICB0eG4gTnVtQXBwQXJncwogICAgICAgIGJ6IG1haW5fYmFyZV9yb3V0aW5nQDUKCm1haW5fYWJpX3JvdXRpbmdAMToKICAgICAgICB0eG5hIEFwcGxpY2F0aW9uQXJncyAwCiAgICAgICAgbWV0aG9kICJzYXlfaGVsbG8oc3RyaW5nKXZvaWQiCiAgICAgICAgc3dhcAogICAgICAgIG1hdGNoIG1haW5fc2F5X2hlbGxvX3JvdXRlQDIKICAgICAgICBiIG1haW5fc3dpdGNoX2Nhc2VfZGVmYXVsdEAzC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
"clear": "I3ByYWdtYSB2ZXJzaW9uIDgKCi8vIGV4YW1wbGVzLmhlbGxvX3dvcmxkLmFyYzRfY29udHJhY3QuSGVsbG9Xb3JsZENvbnRyYWN0LmNsZWFyX3N0YXRlX3Byb2dyYW0oKSAtPiB1aW50NjQ6Cm1haW5fYmxvY2tAMDoKICAgICAgICBpbnQgMQogICAgICAgIHJldHVybgoK"
},
"state": {
"global": {
"num_byte_slices": 0,
"num_uints": 0
},
"local": {
"num_byte_slices": 0,
"num_uints": 0
}
},
"schema": {
"global": {
"declared": {},
"reserved": {}
},
"local": {
"declared": {},
"reserved": {}
}
},
"contract": {
"name": "HelloWorldContract",
"methods": [
{
"name": "say_hello",
"args": [
{
"type": "string",
"name": "name"
}
],
"returns": {
"type": "void"
}
}
],
"networks": {}
},
"bare_call_config": {
"no_op": "CREATE"
}
}
60 changes: 60 additions & 0 deletions examples/hello_world/out/arc4_contract.approval.debug.teal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions examples/hello_world/out/arc4_contract.approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma version 8

// examples.hello_world.arc4_contract.HelloWorldContract.approval_program() -> uint64:
main_block@0:
txn NumAppArgs
bz main_bare_routing@5

main_abi_routing@1:
txna ApplicationArgs 0
method "say_hello(string)void"
swap
match main_say_hello_route@2
b main_switch_case_default@3

main_say_hello_route@2:
txn OnCompletion
!
assert // OnCompletion is NoOp
txn ApplicationID
assert // is not creating
txna ApplicationArgs 1
callsub say_hello
int 1
return

main_switch_case_default@3:
err // reject transaction

main_bare_routing@5:
txn OnCompletion
bnz main_reject_bare_on_completion@7

main_create@6:
txn ApplicationID
!
assert // is creating
int 1
return

main_reject_bare_on_completion@7:
err // reject transaction


// examples.hello_world.arc4_contract.HelloWorldContract.say_hello(name#0: bytes) -> void:
say_hello:
proto 1 0

say_hello_block@0:
frame_dig -1
extract 2 0
byte "Hello "
swap
concat
log
retsub

Loading

0 comments on commit 7cb1339

Please sign in to comment.