我如何获得和实施Wave公钥 Javascript SwaggerUI

问题描述

我的JavaScript代码出现错误,该错误要求从Waves钱包请求公共密钥。你们能帮我得到吗?这是阻止我的代码运行的唯一方法。我需要公共密钥。

我这里有公共密钥,我只需要一种在JavaScript代码中实现它的方法

这是我部署后在Firebase中的错误

登录Firebase:

函数完成的异常:错误:请提供种子或senderPublicKey

在其API中显示https://testnode1.wavesnodes.com/api-docs/index.html 得到 / addresss / publicKey // {publicKey}

这里是链接https://pastebin.com/AqswyjVC

    const functions = require('firebase-functions');
    exports.distributeStakingRewards = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
        const request = require('request')
        //Fetch list of users who has a positive balance for your asset..
        const assetID = 'xxx'
     
        request('https://testnode1.wavesnodes.com/assets/' + assetID + '/distribution',function(err,res,body) {
            if (res.statusCode === 200) {
                const bodyJSON = JSON.parse(body)
                var transfers = []
                for (uid in bodyJSON) {
                    var bal = bodyJSON[uid]
                    //Set minimum balance to get rewarded
                    if (bal >= 1) {
                        var reward = '0.005'
                        var transfer = { recipient: uid,amount: reward }
                        transfers.push(transfer)
                    }
                }
                const waves = require('waves-transactions')
                const nodeUrl = 'https://testnode1.wavesnodes.com/'
                const params = { transfers: transfers,assetId: assetID,attachment: 'Weekly staking rewards payout',timestamp: Date.Now() }
                const signedTx = waves.masstransfer(params,{
                    'privateKey': 'xxxx',}
                )
                const id = signedTx.id
                waves.nodeInteraction.broadcast(signedTx,nodeUrl).then(tx => {
                    //If tx returns null or undefined tx.id will be undefined === false
                    if (tx.id === id) {
                        console.log('Successfully distributed staking rewards for ' + new Date().toDateString() + 'was complete')
                    } else {
                        console.log('Unable to distribute staking rewards for ' + new Date().toDateString())
                    }
                })
            } else {
                console.log('unable to fetch asset distribution ' + err)
            }
        })
    })

解决方法

Javascript

无论何时需要,您都需要传递 publicKey 。根据 Swagger 定义,必须将其作为URL参数传递,如下所示:

let publicKey = 'your-public-key';

request('https://testnode1.wavesnodes.com/addresses/publicKey/' + publicKey,function(err,res,body) {

});

SwaggerUI

如果您想通过 Swagger界面测试请求,则可以在适当的请求下按试试看按钮,并用填写所需的输入,然后按 Execute 按钮。

enter image description here