我正在尝试创建一个使用Waveskeeper对用户进行身份验证的页面。我在chrome上安装了插件wavekeeper,但仍然收到错误消息:ReferenceError:未定义Waves
尝试过铬和勇敢,同样的错误。
$(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)
答案 0 :(得分:1)
您需要正确初始化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>