IOSTスマートコントラクト #1 HelloWorld

IOSTスマートコントラクト #1 HelloWorld:

IOSTプラットフォームのスマートコントラクトは Javascript をサポートしています。


前提条件

IOST 開発環境 設定&インストール


HelloWorld

1 - HelloWorldプログラムの作成 viエディタで新規プログラムを作成します。

# vi helloworld.js 
次のようにコードを入力します。iを押すと入力モードになります。もし、操作がわからなくなったら、一度ESCキーで編集モードを抜けてから、再度iを押してください。

class HelloWorld { 
    init() {} 
        hello(someone) { 
        return "hello, "+ someone 
    } 
} 
 
module.exports = HelloWorld; 
ABIファイルを作成します。

# vi helloworld.abi 
{ 
  "lang": "javascript", 
  "version": "1.0.0", 
  "abi": [ 
    { 
      "name": "hello", 
      "args": [ 
        "string" 
      ] 
    } 
  ] 
} 
2 - HelloWorldプログラムのパブリッシュ

root@1b4f568854fb:/workdir# ./iwallet  --expiration 10000 --gas_limit 1000000 --gas_ratio 1  --server localhost:30002  --account admin  --amount_limit '*:unlimited'  publish helloworld.js helloworld.abi 
sending tx 
time:1547082154089187348 expiration:1547092154089187189 gas_ratio:1 gas_limit:1e+06 actions:<contract:"system.iost" action_name:"SetCode" data:"[\"{\\\"info\\\":{\\\"lang\\\":\\\"javascript\\\",\\\"version\\\":\\\"1.0.0\\\",\\\"abi\\\":[{\\\"name\\\":\\\"hello\\\",\\\"args\\\":[\\\"string\\\"]}]},\\\"code\\\":\\\"class HelloWorld {\\\\n    init() {}\\\\n    hello(someone) {\\\\n        return \\\\\\\"hello, \\\\\\\"+ someone\\\\n    }\\\\n}\\\\n\\\\nmodule.exports = HelloWorld;\\\\n\\\"}\"]" > amount_limit:<token:"*" value:"unlimited" > publisher:"admin" publisher_sigs:<algorithm:ED25519 signature:"x\327!F:\t\250\036\301M\345W{\303\265&\027\225\216\035\244\315\377][*\300\356\257\353\327\263[\036\2439\342D\327\037.R\273%\203\204Wj7\241\237\366Qi%\013t~\206\306\004#\007\001" public_key:"\350\022\265.\251\255\\\272\232\232\360:\374\306\362\224*E$\260\337<\003D\334\031Pr\203\026p\304" > 
Sending tx to rpc server finished. The transaction hash is: 3xDYF2aPBmpcRNyVV8QdpQXeDxb6jdkWzpQ5sUmuNBhK 
exec tx done 
{ 
    "txHash": "3xDYF2aPBmpcRNyVV8QdpQXeDxb6jdkWzpQ5sUmuNBhK", 
    "gasUsage": 36269, 
    "ramUsage": { 
        "admin": "356", 
        "system.iost": "148" 
    }, 
    "statusCode": "SUCCESS", 
    "message": "", 
    "returns": [ 
        "[\"Contract3xDYF2aPBmpcRNyVV8QdpQXeDxb6jdkWzpQ5sUmuNBhK\"]" 
    ], 
    "receipts": [ 
    ] 
} 
The contract id is Contract3xDYF2aPBmpcRNyVV8QdpQXeDxb6jdkWzpQ5sUmuNBhK 
HelloWorldプログラムの実行

root@1b4f568854fb:/workdir# ./iwallet  --expiration 10000 --gas_limit 1000000 --gas_ratio 1  --server localhost:30002  --account admin  --amount_limit '*:unlimited'  call "Contract3xDYF2aPBmpcRNyVV8QdpQXeDxb6jdkWzpQ5sUmuNBhK" "hello" '["developer"]' 
sending tx time:1547082303623287782 expiration:1547092303623287681 gas_ratio:1 gas_limit:1e+06 actions:<contract:"Contract3xDYF2aPBmpcRNyVV8QdpQXeDxb6jdkWzpQ5sUmuNBhK" action_name:"hello" data:"[\"developer\"]" > amount_limit:<token:"*" value:"unlimited" > publisher:"admin" publisher_sigs:<algorithm:ED25519 signature:"\253\007\307\024\334s\370\302\r8\246\333\334mhs\255-\007:]\301&d\360\231\2327p\314\226Z/\016\306\364{\307\251\346\307c\024\232\037\243\003]0\253k;\202\022\245\207\232d\210\225u=\252\010" public_key:"\350\022\265.\251\255\\\272\232\232\360:\374\306\362\224*E$\260\337<\003D\334\031Pr\203\026p\304" > sending tx 
time:1547082303623287782 expiration:1547092303623287681 gas_ratio:1 gas_limit:1e+06 actions:<contract:"Contract3xDYF2aPBmpcRNyVV8QdpQXeDxb6jdkWzpQ5sUmuNBhK" action_name:"hello" data:"[\"developer\"]" > amount_limit:<token:"*" value:"unlimited" > publisher:"admin" publisher_sigs:<algorithm:ED25519 signature:"\253\007\307\024\334s\370\302\r8\246\333\334mhs\255-\007:]\301&d\360\231\2327p\314\226Z/\016\306\364{\307\251\346\307c\024\232\037\243\003]0\253k;\202\022\245\207\232d\210\225u=\252\010" public_key:"\350\022\265.\251\255\\\272\232\232\360:\374\306\362\224*E$\260\337<\003D\334\031Pr\203\026p\304" > 
send tx done 
the transaction hash is: 3ibCnq5E64jMjPXqTU3bFgsZQkbFeFyZM9cCKUcoFGCf 
exec tx done 
{ 
    "txHash": "3ibCnq5E64jMjPXqTU3bFgsZQkbFeFyZM9cCKUcoFGCf", 
    "gasUsage": 33084, 
    "ramUsage": { 
    }, 
    "statusCode": "SUCCESS", 
    "message": "", 
    "returns": [ 
        "[\"hello, developer\"]" 
    ], 
    "receipts": [ 
    ] 
} 
4 - レシートの取得

root@1b4f568854fb:/workdir# ./iwallet receipt 3ibCnq5E64jMjPXqTU3bFgsZQkbFeFyZM9cCKUcoFGCf 
{ 
    "txHash": "3ibCnq5E64jMjPXqTU3bFgsZQkbFeFyZM9cCKUcoFGCf", 
    "gasUsage": 33084, 
    "ramUsage": { 
    }, 
    "statusCode": "SUCCESS", 
    "message": "", 
    "returns": [ 
        "[\"hello, developer\"]" 
    ], 
    "receipts": [ 
    ] 
} 


協力

Dr.和田隆夫 CTO エバーシステム株式会社
MEET IOST 開発者コミュニティ

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)