-
Notifications
You must be signed in to change notification settings - Fork 1
/
my_token.py
30 lines (22 loc) · 908 Bytes
/
my_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#my_token
#Smart Contract State
S = Hash(default_value=0)
#This runs when our contract is created on the blockchain, and never again.
@construct
def seed():
S['me'] = 50
#This method will be exported so our users can call it
@export
def transfer(amount: int, receiver: str):
#ctx.caller is the verified identity of the person who signed this transaction
#we will keep this reference as the "sender" of the transaction
sender = ctx.caller
#get the sender's balance from State
balance = S[sender]
#assert the sender has the appropriate balance to send
#if this assert fails the method will fail here, all values revert and no more code is executed
assert balance >= amount, "Transfer amount exceeds available token balance"
#deducte the tokens from the sender's balance
S[sender] -= amount
#add tokens to the reciever's balance
S[receiver] += amount