create account

steemjs初体验 / 网络研习社#41 by lemooljiang

View this thread on: hive.blogpeakd.comecency.com
· @lemooljiang ·
$8.31
steemjs初体验 / 网络研习社#41
![steemjs.jpg](https://cdn.steemitimages.com/DQmbdmE4GrpMZygdzqEtCHYnmm8UpMiNsHHWouWwptw9nwi/steemjs.jpg)

有了前面Vue前端开发的一些基础,就可以试着用steemjs来开发一些应用了。

查看下steemjs的开发文档 https://github.com/steemit/steem-js/tree/master/doc#install ,除了会安装之外,确实不知怎么做,难怪村长 @ericet 要自己动手写开发文档了。参考村长的文章 [《怎么用JS写个发帖程序》](https://steemit.com/cn/@ericet/anrhy-js) ,还有另一位作者 @lonelywolf 的文章 [SteemJS手册](https://steemit.com/utopian-io/@lonelywolf/steemjs-full-tutorial-all-the-functions-all-the-abilities) ,几篇文章对照着一起看,倒也基本上弄明白怎么做了。

使用steemjs大概要四步:
1. 安装steemjs的包
当然前提是已经有了Nodejs环境,Vue也能跑起来。`install steem --save` ,这么一步就可以装上steemjs了。
2. 导入
`import  steem from 'steem'`
3. 连接API
`steem.api.setOptions({ url: 'https://api.steemit.com' });`
4. 使用
到了这里就可以正常使用API的各种方法了,比如发个贴,点个赞什么的。用它发个贴试试。
```js
steem.broadcast.comment(
  "5KYYsbK34wZXXXXXXXXXXXXXXXXXXXXXXXXL",
  "",
  "test",
  "cn-book",
  "cn-test-2019",
  "it's a test",
  "steemjs test post",
  '{"tags": "test", "app": "steemit/0.1", "users": ["cn-book"], "format": "markdown"}',
  function(err, result) {
    console.log(123, err, result);
  });
```

好了,发贴成功了,去网站看看效果吧, https://steemit.com/test/@cn-book/cn-test-2019
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
👎  
properties (23)
authorlemooljiang
permlinksteemjs-41
categorycn
json_metadata{"tags":["cn","network-institute","steemjs","steemdev","steem"],"users":["ericet","lonelywolf"],"image":["https://cdn.steemitimages.com/DQmbdmE4GrpMZygdzqEtCHYnmm8UpMiNsHHWouWwptw9nwi/steemjs.jpg"],"links":["https://github.com/steemit/steem-js/tree/master/doc#install","https://steemit.com/cn/@ericet/anrhy-js","https://steemit.com/utopian-io/@lonelywolf/steemjs-full-tutorial-all-the-functions-all-the-abilities","https://steemit.com/test/@cn-book/cn-test-2019"],"app":"steemit/0.1","format":"markdown"}
created2019-10-13 12:05:57
last_update2019-10-13 12:05:57
depth0
children3
last_payout2019-10-20 12:05:57
cashout_time1969-12-31 23:59:59
total_payout_value4.207 HBD
curator_payout_value4.106 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,136
author_reputation438,608,506,193,732
root_title"steemjs初体验 / 网络研习社#41"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,510,327
net_rshares26,761,397,889,905
author_curate_reward""
vote details (42)
@kissfirer ·
@tipu curate
properties (22)
authorkissfirer
permlinkpzbb70
categorycn
json_metadata{"tags":["cn","palnet","zzan","dblog","mediaofficials","actnearn","marlians","neoxian","lassecash","upfundme","sct","sct-cn","sct-freeboard"],"users":["tipu"],"app":"steemcn/0.1"}
created2019-10-13 12:11:27
last_update2019-10-13 12:11:27
depth1
children1
last_payout2019-10-20 12:11:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length12
author_reputation34,102,186,883,790
root_title"steemjs初体验 / 网络研习社#41"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,510,448
net_rshares0
@tipu ·
<a href="https://tipu.online/curator?kissfirer" target="_blank">Upvoted &#128076;</a>
properties (22)
authortipu
permlinkre-pzbb70-20191013t121153
categorycn
json_metadata""
created2019-10-13 12:11:54
last_update2019-10-13 12:11:54
depth2
children0
last_payout2019-10-20 12:11:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation55,930,870,950,106
root_title"steemjs初体验 / 网络研习社#41"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,510,455
net_rshares0
@scisan ·
$0.15
学习下!
👍  
properties (23)
authorscisan
permlinkpzbl2p
categorycn
json_metadata{"app":"steemit/0.1"}
created2019-10-13 15:44:51
last_update2019-10-13 15:44:51
depth1
children0
last_payout2019-10-20 15:44:51
cashout_time1969-12-31 23:59:59
total_payout_value0.073 HBD
curator_payout_value0.073 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4
author_reputation-1,481,395,934,280
root_title"steemjs初体验 / 网络研习社#41"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id91,516,142
net_rshares767,230,214,414
author_curate_reward""
vote details (1)