Contract con_eh_test_1


Contract Code


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

Byte Code

e300000000000000000000000005000000400000007332000000650064006401640264038d035a016404640584005a026503640183016504650564069c0264076408840483015a0664095300290ae900000000da0d636f6e5f65685f746573745f31da01532903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65630000000000000000000000000300000043000000730c0000006401740064023c006400530029034ee932000000da026d652901da035f5f53a900720a000000720a000000da00da045f5f5f5f0400000073020000000001720c0000002902da06616d6f756e74da087265636569766572630200000000000000040000000400000043000000734200000074006a017d0274027c0219007d037c037c006b05731e740364018301820174027c02050019007c00380003003c0074027c01050019007c00370003003c006400530029024e7a2f5472616e7366657220616d6f756e74206578636565647320617661696c61626c6520746f6b656e2062616c616e63652904da03637478da0663616c6c65727209000000da0e417373657274696f6e4572726f722904720d000000720e000000da0673656e646572da0762616c616e6365720a000000720a000000720b000000da087472616e7366657208000000730a0000000002060108011001100172140000004e2907da04486173687209000000720c000000da085f5f6578706f7274da03696e74da037374727214000000720a000000720a000000720a000000720b000000da083c6d6f64756c653e0100000073060000000e0308040601