使用 Waveskeeper 进行身份验证:如何修复 'Waves is not defined'
Authenticating with Waveskeeper: How to fix 'Waves is not defined'
我正在尝试创建一个使用 Waveskeeper 对用户进行身份验证的页面。我在 chrome 上安装了插件 wavekeeper 但我一直收到错误:ReferenceError: Waves is not defined
试过 chrome 和勇敢,同样的错误。
$(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)
您需要正确初始化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>
我正在尝试创建一个使用 Waveskeeper 对用户进行身份验证的页面。我在 chrome 上安装了插件 wavekeeper 但我一直收到错误:ReferenceError: Waves is not defined
试过 chrome 和勇敢,同样的错误。
$(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)
您需要正确初始化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>