Bot Build #8 - Upvote&Resteem by payment
Repository
e.g. https://github.com/steemit/steem-js
What Will I Learn?
- Create Upvote&Resteem based on payment
Requirements
- Node.JS, Here
- Steem Package (Install: npm install steem --save)
Difficulty
- Intermediate
Tutorial Contents
You will learn how to create Upvote&Resteem service based on payment
Curriculum
- Bot Build #1
- Bot Build #2
- Bot Build #3
- Bot Build #4
- Bot Build #5
- Bot Build #6
- Bot Build #7
- SteemJS Tutorials #1
- NodeJS Tutorials #1
The Tutorial
Step 1 - Setup, Variables & Functions
first of all, we need to set-up the base, the functions, and the variables.
so as always, we need account name & wif variables.
we need WEIGHT(base weight) variable and PAYMENT variables.
the WEIGHT variable will be our base weight that the bot will vote with.
the PAYMENT variable will be the base payment for the resteem&upvote (note: anything higher than the payment will be donation)
const ACC_NAME = 'guest123', // Account Name
ACC_KEY = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg'; // Account Active WIF
const PAYMENT = 0.5, // The Resteem&Upvote Payment Amount (Higher than this number = donation).
WEIGHT = 5; // Voting Weight
to make it "better" you can connect to custom stable WebSocket
steem.api.setOptions({ url: 'wss://rpc.buildteam.io' }); //Connecting To Custom WebSocket
to make it cleaner and fancy you can add comments to the console at the start
console.log('Upvote&Resteem by payment Bot Script Running...');
console.log('Waiting for payment...');
so after we're done with all of that we need the functions,
one function will check the payment and start the process,
one function will send the transfers (messages/refunds),
and two functions will send the vote and resteem the post.
Note
: I'm not going to explain about the vote/resteem/transfer
functions because I already talk about them at the last tutorials, you can check them to get a better explanation.
// This Function Check The Payment And Send The Resteem & Upvote.
function checkPayment(amount, url, author) {
}
// Send Transfer Function
function SendTransfer(Name, Memo, Amount) {
Amount = Amount.toString() + ' SBD';
steem.broadcast.transfer(ACC_KEY, ACC_NAME, Name, Amount, Memo, function(err, result) {
console.log(err, 'Sent ' + Amount + ' To ' + Name + ' With The Memo: ' + Memo
);
});
}
// Send Vote Function
function streamVote(author, permalink, weight) {
steem.broadcast.vote(ACC_KEY, ACC_NAME, author, permalink, weight, function(err, result) {
console.log('Voted Succesfully, permalink: ' + permalink + ', author: ' + author + ', weight: ' + weight / 1000 + '%.', err);
});
}
// Resteem Post Function
function streamResteem(ACC, permlink, author) {
const json = JSON.stringify([
'reblog',
{
account: ACC,
author: author,
permlink: permlink
}
]);
steem.broadcast.customJson(ACC_KEY, [], [ACC], 'follow', json, (err, result) => {
console.log('Resteemed Post: ' + permlink + ' Successfully!', err);
});
}
simply, streamVote will send the vote, streamResteem will resteem the post and sendTransfer will send transfer with the amount, memo and to the sender.
Step 2 - Check The Payment (Fill The Functions)
first of all, we need to check if the amount is less than our PAYMENT (variable)
if (amount < PAYMENT) {
console.log('Wrong Payment, reason: amount is less than the payment');
SendTransfer(
author, 'Hey ' + author + ', Minimum Payment is: ' + PAYMENT + ', You sent: ' + amount, amount);
}
if it's lower than the payment it will be sent back to the sender.
if it's higher or equal to the PAYMENT (Variable) we can start the process
else {
console.log('Payment Succeed From ' + author + ', Resteem & Upvoted.');
SendTransfer(author, 'Thank you for using our service, your post resteemd and upvoted by the bot!', 0.001);
url = url.split('/');
let permlink = url[5],
Author = url[4].split('@')[1];
console.log(url[0]);
streamVote(Author, permlink, WEIGHT * 1000);
streamResteem(ACC_NAME, permlink, Author);
}
first, we send a comment to the console, then we send transfer thank you for using ....
with 0.001 SBD (message), then we get the permalink and the author(the account that creates the post), then we stream the vote and resteem the post.
easy enough, right?
Step 3 - The End, listen to streamTransactions
first, we need to listen for the transactions
steem.api.streamTransactions('head', function(err, result) {
const type = result.operations[0][0];
const data = result.operations[0][1];
}
this function will listen to every transaction that goes through steem blockchain.
type
- is the type of the transaction
data
- is the data that comes with the transactions
we need to check if the type is transfer
and if the receiver is our account
name.
if (type == 'transfer' && data.to == ACC_NAME) {
//Checking Transaction Type & Reciever Name
console.log('Incoming Payment From ' + data.from + ', Amount: ' + data.amount);
}
Note
: STEEM transactions = donation
so let's check if the amount is a steem transaction or sbd.
if it's steem we will send thank you
message and take the donation.
if (data.amount.split(' ')[1] == 'STEEM') {
// Checking The Token Type
SendTransfer(
data.from,
'Thanks for your donation, we really appreciate that. if this is not a donation please contact us!',
0.001
); // Sending Donation Transfer ("Thank you")
console.log('Donation From ' + data.from + ', ' + data.amount);
}
if it's not we will check if the memo is an URL (steemit URL) and we will send the checkPayment function to check the payment and start the process
else {
if (data.memo.split('/')[0] != 'https:') {
console.log('Incoming Donation / Other Transfer');
} else {
console.log('Starting Payment Proccess! Author: ' + data.from);
checkPayment(data.amount.split(' ')[0], data.memo, data.from);
}
if it's not url it will be other transfer or a donation most of the times.
if it's a steemit URL(URL) we will send a comment to the console and start the function.
and here we're done!
if you want new tutorials give me a comment with suggestion for a script and I'll do that!
Have a great day!
You can check the full work at my repl.it account and other bots that I create!
Proof of Work Done
the work made in Repl.it, https://repl.it/@lonelywolf22/Steem-Bots-UpvoteandResteem-by-payment-V01-Done
user: https://repl.it/@lonelywolf22
GitHub: https://github.com/lonelywolf1
Utopian Tutorials GitHub Repository: https://github.com/lonelywolf1/Bot-Projects-SteemJS (This tutorial will add to the github repository in the next few hours!)
Thanks for the contribution.
Link to the Answers of the Questionnaire -
Click here
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Hey @lonelywolf
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!