Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
    <!-- スタイルシートの読み込み -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.2/css/bulma.min.css">
    <!-- スタイルシートの読み込み -->

    <!-- 「iost.min.js」の読み込み -->
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/iost@0.1.22/dist/iost.min.js"></script>
    <!-- 「iost.min.js」の読み込み -->

    <section class="section">
        <div class="container">

            <div id="log"></div>
            <div id="suc"></div>

            <div class="notification is-info">
                Chrome拡張機能ウォレット「iWallet」が<strong>インストール済みで</strong>ウォレットの<strong>ロックが解除</strong>されていれば、ウォレットにインポートしているアカウント情報が表示されます。
            </div>


            <div class="card">
                <div class="card-content">

                    <span class="tag is-black" id="login">利用できるアカウントはありません</span>
                    <div class="field">
                        <label class="label">送金先アカウントID</label>
                        <div class="control">
                            <input class="input" type="text" id="account_to" placeholder="送付先IDを入力">
                        </div>
                    </div>

                    <div class="field">
                        <label class="label">送金量</label>
                        <div class="control">
                            <input class="input" type="text" id="amount" placeholder="送金量">
                        </div>
                    </div>

                    <div class="field">
                        <label class="label">メモの内容</label>
                        <div class="control">
                            <input class="input" type="text" id="memo" placeholder="メモの値を入力">
                        </div>
                    </div>

                    <button class="button is-primary" onclick="transfer()">送金の実行</button>
                    <p class="help is-danger">※サンプルのため、バリデーションチェックは入れておりません。送金量に数字半角以外を入れるとiWalletが起動しません。</p>

                </div>
                <!-- フッター -->
                <footer class="card-footer">
                    <p class="card-footer-item">
                        <span>
                            <a href="https://developers.iost.io/docs/ja/1-getting-started/Overview.html" target="_blank"
                                rel="noopener noreferrer">IOST開発ドキュメント</a>
                        </span>
                    </p>
                    <p class="card-footer-item">
                        <span>
                            <a href="https://github.com/iost-official" target="_blank"
                                rel="noopener noreferrer">IOSTのGitHub</a>
                        </span>
                    </p>
                </footer>
                <!-- フッター -->

            </div>

        </div>

    </section>

</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                function log(msg, flg) {
    document.getElementById('suc').innerHTML = '';
    var p = document.createElement('p');
    p.innerHTML = msg;

    if ('suc' == flg) {
        document.getElementById('suc').appendChild(p);
        document.getElementById('suc').className = "notification is-success";
        return;
    }

    document.getElementById('log').innerHTML = '';
    document.getElementById('log').appendChild(p);
    document.getElementById('log').className = "notification is-danger";
}

var transfer;
var flg;

document.addEventListener(
    // 500ミリ秒=0.5秒ごとにIOSTアカウント情報を取得するための時間設定
    "DOMContentLoaded", async function (event) {
        await new Promise(done => setTimeout(() => done(), 500));

        // ここでChrome拡張機能のウォレット(IOSTアカウント)情報を取得
        IWalletJS.enable().then(
            function (account_from) {
                // 【取得できない(空)】なら後の処理はしない
                if (!account_from) return;
                // 【取得できた】なら画面に表示
                document.getElementById('login').innerHTML = "現在使用されているIOSTアカウントは「" + account_from + "」です";

                // IOST送金のための処理を始めるための準備
                const iost = IWalletJS.newIOST(IOST);

                // ここから「送金の実行」が押された後の処理が始まります。
                transfer = function () {
                    // テキストフィールドの値取得
                    const account_to = document.getElementById("account_to").value;
                    const amount = document.getElementById("amount").value;
                    const memo = document.getElementById("memo").value;

                    // トランザクション(この場合は送金)内容の設定
                    const tx = iost.callABI("token.iost", "transfer", ["iost", account_from, account_to, amount, memo]);

                    // 送金内容の反映(Chrome拡張機能ウォレットが起動)
                    tx.addApprove("iost", amount);
                    console.log(tx.getApproveList());

                    // 送金処理実行後の分岐
                    iost.signAndSend(tx)
                        // 【送金が成功した場合】トランザクションIDが取得できます。
                        .on('pending', function (txid) {
                            flg = "pen";
                            log("トランザクションID: " + txid, flg);
                        })
                        // 【送金が成功した場合】トランザクションの内容(レシート)が取得できます。
                        .on('success', function (result) {
                            flg = "suc";
                            log("送金結果: " + JSON.stringify(result), flg);
                        })
                        // 【送金が失敗した場合】エラー文言を取得または表示できます。
                        .on('failed', function (failed) {
                            flg = "fai";
                            log("送金失敗:ユーザーが署名要求を拒否しました→原文「 " + JSON.stringify(failed) + "」", flg);
                        })
                }

            }
        )
    }
)
              
            
!
999px

Console