I am getting a error in my JavaScript code, which is requesting a public key from my Waves wallet. Can you guys help me to get that? It's the only thing preventing my code from running. I need the public key.
I have the public key here with me, I just need a way to implement that in my JavaScript code.
This is the error in Firebase after I deploy:
logs in Firebase:
Exception from a finished function: Error: Please provide either seed or senderPublicKey
in their API shows: https://testnode1.wavesnodes.com/api-docs/index.html GET /addresses/publicKey/{publicKey}
Here is the link : 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
You need to pass the publicKey whenever the request need it. Acording to the Swagger definition, it must be passed as URL parameter like so:
SwaggerUI
If you want to test the request through the Swagger Interface you can press the button Try it out under the proper request, fill the required input with the public key and then press the button Execute.