怎么用JS写个STEEM转账程序?

怎么用JS写个STEEM转账程序?



(Image source: Pixabay)

有没有好奇NBC每日的自动分红程序是怎么实现的?或者那些给很多账号发送0.001 STEEM打小广告的程序是怎么实现的?

在steemjs里,提供了一个function用于转账:

steem.broadcast.transfer(wif, from, to, amount, memo, function(err, result) {
  console.log(err, result);
});

你只需填入相应的信息就可以进行转账了。比如我想给team-cn发送0.001 STEEM,并留言hello:

steem.broadcast.transfer(活动密钥, ericet, team-cn, '0.001 STEEM', 'hello', function(err, result) {
  console.log(err, result);
});

只需几行代码,一个简单的转账程序就写好了。

是不是有点过于简单?那加点难度,比如给多个账号发送0.001 STEEM,就像打小广告的程序一样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const steem = require('steem');
const accounts =['team-cn','steem-drivers','teamcn-shop']; //要转账的账号
const myAccount='ericet'; //你的账号
const wif='活动密钥';
const memo='hello'; //附言


for (let i in accounts) {
transfer(accounts[i]);
}
function transfer(account) {
steem.broadcast.transfer(wif, myAccount, account, '0.001 STEEM', memo, function (err, result) {
console.log(err, result);
});
}

运行以上代码,就会自动给team-cn,steem-drivers和teamcn-shop转0.001 STEEM并且附言“hello”:

image.png

是不是很简单?


STEEM编程系列:


This page is synchronized from the post: ‘怎么用JS写个STEEM转账程序?’

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×