In this tutorial we will learn how to send SBD using SteemJS which is the JavaScript API for Steem blockchain. We will use steemjs and jquery to accomplish this task.
First thing we will do is setting up the html page for the input fields:
It will accept the following inputs:
Text box for user sending the money.
Password field for Private active/owner key for the user sending the money.
The last step is to setup the javascript function that calls the steemjs function steem.broadcast.transfer.
This function has 4 input parameters:
wif --> value of password field txtActiveKey.
from --> Value of textbox txtFromUser.
to --> Value of textbox txtToUser.
amt --> Value of textbox txtSBDAmount. This needs to be formatted to 3 decimal places.
memo --> blank string in this case.
Here is the script to capture the input using jquery and call the steemjs email.
$(document).ready(function () {
$("#btnSendSBD").click(function () {
var from = $("#txtFromUser").val();
var wif = $("#txtActiveKey").val();
var ul = document.getElementById('result');
var amt = parseFloat($("#txtSBDAmount").val()).toFixed(3) + " SBD";
var to = $("#txtToUser").val();
steem.broadcast.transfer(wif, from, to, amt, "", function (sendError, sendResult)
{
console.log(sendError, sendResult);
if (sendError != null)
{
console.log(sendError);
var li = document.createElement('li');
li.innerHTML = to + ' Send SBD Error';
ul.appendChild(li);
}
else {
var li = document.createElement('li');
li.innerHTML = from + ' sent ' + amt + ' to ' + to ;
ul.appendChild(li);
}
});
});
});