怎么用JS发送Custom Json到STEEM区块链上?

in #cn7 years ago (edited)

前几天阿John @john371911 在村里询问有什么工具可以发Custom Json?查了一下,没看到任何工具可以用于发送Custom Json的,所以最好的办法就是自己写一个。

Custom Json是什么呢?

其实就是把一些自己想写的信息写到区块链上。这个Custom Json用的最多的是基于STEEM的DApps。比如Steemmonsters,Steem-engine等等

Steemmonsters会把每次的对战信息,获得的奖励卡等信息以Custom Json的格式发送到STEEM区块链上

而Steem-engine会把每笔交易,转账,领取奖励等信息都以Custom Json的格式写入到STEEM区块链

Custom Json长什么样子呢?

Custom Json包含:id,json,required_auths,和required_posting_auths 这4个元素

  • id: 这个custom json的名字,比如,我可以写个custom json命名为"ericet_json"
  • json: 这个是你想写入的信息以json格式保存
  • required_auths: 活动密钥认证。比如你想用custom json做DApp的转账,这里就需要活动密钥认证了。
  • required_posting_auths:发帖密钥认证。领取奖励,发起对战这些对你钱包没啥影响的,只需发帖密钥认证就好了。

了解了Custom Json的基本结构就可以开始写了。

steemjs提供了一个function用于发送Custom Json:

  steem.broadcast.customJson(
    "",//密钥
    [], // Required_auths
    [], // Required Posting Auths
    '', // Id
    json, //json
    function(err, result) {
      console.log(err, result);
    }
  );

比如你想写个程序自动领取SCT的收益:

const steemid = 'ericet';
const postingKey='xxxxxxxxxxxxxxxx';
let json = JSON.stringify({
        symbol: 'SCT'
    });

steem.broadcast.customJson(postingKey, [], [steemid], 'scot_claim_token', json, (err, result) => {
    if (err)
        console.log(err);
    else
        console.log(steemid + " just claimed SCT token");
});

这个自动领取收益程序一次只能领取一个币,如果你想一次领取所有的代币,可以看JS版一次领取所有代领取SCOT代币

你还可以自己创建一个属于自己的Custom Json:

const steem = require('steem');
const steemid = 'ericet';
const postingKey='xxxxxxxxxxxxxx';

let json = JSON.stringify({
        random: '只是随机的一个Custom Json',
        author: '新手村村长'
    });

steem.broadcast.customJson(postingKey, [], [steemid], 'ericet_json', json, (err, result) => {
    if (err)
        console.log(err);
    else
        console.log(result);
});

运行后,就会发送以下custom json到STEEM链上。这个custom json没有任何用途。

image.png

现在越来越多的DApps在使用Custom Json来保存信息,你只需了解他们的json的格式,完全可以不登陆steemmonsters游戏的情况下,使用custom json发起对战。

Custom Json的玩法还有很多,比如通过custom json锁仓/代理/转账/出售/购买SCOT代币。这些就留着你们自己去探索。


STEEM编程系列:

Sort:  

感谢代理1009.85SP 给team-cn! 由于你使用CN作为你的首标签,额外获得2%点赞! 你的帖子获得team-cn 27% 点赞!(如果不想看到这个回复,请回复“取消”)

你好鸭,村长!

@hertz.diy给您叫了一份外卖!

@pet.society 小米高 迎着大雪 骑着熊熊 给您送来
双色馒头

吃饱了吗?跟我猜拳吧! 石头,剪刀,布~

如果您对我的服务满意,请不要吝啬您的点赞~
@onepagex

真羡慕会编程序的高手
!shop

你今天过的开心吗?你好!家中可愛的寵物照想要跟大家分享嗎?或是出去玩拍到一些可愛的動物,別忘了到@dpet分享,可以得到@dpet的獎勵喔!倘若你想让我隐形,请回复“取消”。

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 98 contributions, your post is ranked at #13.

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

什麼時候會有個
「怎麼用JS寫個STEEMMONSTERS自動戰鬥機械人?」

我写过自动发帖自动发起战斗的程序,对战可能有点难度

Posted using Partiko iOS

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 central hub for DIY and How-To projects. It's an opportunity to find and share the latest in DIY, and How-To tutorials. The recommended tags required when creating a DIY artcle are #diy, #build-it. #how-to, or #doityourself. Please read our guide

Need help? Live technical support on Discord or Telegram

|


This project is run and supported by our witness @gulfwaves.net. If you like what we do, click here to vote for us





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.05
TRX 0.32
JST 0.083
BTC 62530.78
ETH 1673.29
USDT 1.00
SBD 0.42