2

我正在尝试创建一个使用 Waveskeeper 对用户进行身份验证的页面。我在 chrome 上安装了插件 wavekeeper,但我不断收到错误消息:ReferenceError: Waves is not defined

试过chrome和brave,同样的错误。


    $(document).ready ( function () 
    {

        /*
        if(typeof Waves !== 'undefined'){
            alert("Waves Keeper not installed or loaded.");
            console.log('installed')
        }else{
            alert("Waves Keeper not installed or loaded.");
            console.log('not installed')
            return
        }
        */
        console.log('Start');
        console.log(Waves);
        WavesKeeper.initialPromise
        .then((keeperApi) => { 
            /*...init app*/        
            console.log(WavesKeeper);
            keeperApi.publicState().then( state => startApp(state));
        })

        function startApp(state)
        {

            $('#address').text(state.account.address);
            $('#balance').text(state.account.balance.available*1e-8);
            $('#network').text(state.network.code);
        }
    ```

I am receiving this error:

jquery-3.4.0.min.js:2 jQuery.Deferred exception: Waves is not defined ReferenceError: Waves is not defined
    at HTMLDocument.<anonymous> (http://localhost/test/wk.html:20:17)
    at e (https://code.jquery.com/jquery-3.4.0.min.js:2:29453)
    at t (https://code.jquery.com/jquery-3.4.0.min.js:2:29755) undefined
k.Deferred.exceptionHook @ jquery-3.4.0.min.js:2
t @ jquery-3.4.0.min.js:2
setTimeout (async)
(anonymous) @ jquery-3.4.0.min.js:2
c @ jquery-3.4.0.min.js:2
fireWith @ jquery-3.4.0.min.js:2
fire @ jquery-3.4.0.min.js:2
c @ jquery-3.4.0.min.js:2
fireWith @ jquery-3.4.0.min.js:2
ready @ jquery-3.4.0.min.js:2
B @ jquery-3.4.0.min.js:2
jquery-3.4.0.min.js:2 Uncaught ReferenceError: Waves is not defined
    at HTMLDocument.<anonymous> (wk.html:20)
    at e (jquery-3.4.0.min.js:2)
    at t (jquery-3.4.0.min.js:2)

4

1 回答 1

2

您需要正确初始化 WavesKeeper 和 keeperAPI,这就是它不能被引用的原因。

试试这个代码:

<script>
        window.WavesKeeper = Waves;

        $('document').ready(function () {
            if (typeof Waves !== 'undefined') {
                console.log('installed')
            } else {
                console.log('not installed')
            }
            $('.auth-btn').on('click', function (e) {
                WavesKeeper.auth({ name: 'Your App', data: 'Any stuff' })
                    .then(function (res) {
                        console.log(res);
                        $('#address')
                            .html('Your WAVES Address: <b>' + res.address + '</b>')
                            .removeClass('alert-danger').addClass('alert-success');
                    })
                    .catch(function (err) {
                        $('#address').html(JSON.stringify(err)).removeClass('alert-success').addClass('alert-danger');
                    });
                e.preventDefault();
            });

        });
    </script>

<a class="btn btn-primary btn-rounded auth-btn" href="#">Click to get WAVES Address</a>
        <div class="alert alert-success" id="address"></div>
于 2019-05-25T15:33:24.353 回答