-
Notifications
You must be signed in to change notification settings - Fork 43
/
app.js
56 lines (52 loc) · 2.04 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const dsteem = require('dsteem');
let opts = {};
//connect to production server
opts.addressPrefix = 'STM';
opts.chainId =
'0000000000000000000000000000000000000000000000000000000000000000';
//connect to server which is connected to the network/production
const client = new dsteem.Client('https://api.steemit.com');
//submitAcc function from html input
const max = 5;
window.submitAcc = async () => {
const accSearch = document.getElementById('username').value;
const _account = await client.database.call('get_accounts', [[accSearch]]);
console.log(`_account:`, _account);
const name = _account[0].name;
const steem_balance = _account[0].balance;
const balance = `Available Steem balance for ${name}: ${steem_balance}<br/>`;
document.getElementById('accBalance').innerHTML = balance;
document.getElementById('steem').value = steem_balance;
const receiver = document.getElementById('receiver').value;
document.getElementById('sc').style.display = 'block';
const link = `https://steemconnect.com/sign/transfer-to-vesting?from=${name}&to=${receiver}&amount=${steem_balance}`;
document.getElementById('sc').innerHTML = `<br/><a href=${encodeURI(
link
)} target="_blank">Steemconnect signing</a>`;
};
window.submitTx = async () => {
const privateKey = dsteem.PrivateKey.fromString(
document.getElementById('wif').value
);
const op = [
'transfer_to_vesting',
{
from: document.getElementById('username').value,
to: document.getElementById('receiver').value,
amount: document.getElementById('steem').value,
},
];
client.broadcast.sendOperations([op], privateKey).then(
function(result) {
document.getElementById('result').style.display = 'block';
document.getElementById(
'result'
).innerHTML = `<br/><p>Included in block: ${
result.block_num
}</p><br/><br/>`;
},
function(error) {
console.error(error);
}
);
};