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

in #cn7 years ago (edited)



(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,就像打小广告的程序一样:

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编程系列:

Sort:  

Hi @ericet!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 4.693 which ranks you at #1669 across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 116 contributions, your post is ranked at #15.

Evaluation of your UA score:
  • Some people are already following you, keep going!
  • The readers appreciate your great work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

Hi, @ericet!

Thank you for using the #build-it tag. This post has been rewarded with BUILD tokens in the form of an upvote.

Build-it is a new tribe on the steem blockchain that serves as a central hub for DIY and How-to's contents on steemit. The recommended tags required when creating a DIY artcle are #diy, #build-it. #how-to, or #doityourself. You'll get rewarded with BUILD tokens, which can also be exchanged for steem on steem-engine when you use any of the recommended tags as well as posting via our website.

We encourage steemians to post their DIY articles via our website. Have a question? Join us on Discord and telegram

This project is run and supported by our witness @gulfwaves.net. If you like what we do, vote for us as a witness on the steem blockchain



This post has been voted on by the SteemSTEM curation team and voting trail. It is elligible for support from @curie and @minnowbooster.

If you appreciate the work we are doing, then consider supporting our witness @stem.witness. Additional witness support to the curie witness would be appreciated as well.

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Please consider using the steemstem.io app and/or including @steemstem in the list of beneficiaries of this post. This could yield a stronger support from SteemSTEM.

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.082
BTC 60573.65
ETH 1550.46
USDT 1.00
SBD 0.47