customJson可以用来保存DAPP自定义的数据,格式为json。
steem.broadcast.customJson(wif, requiredAuths, requiredPostingAuths, id, json, function(err, result) {
console.log(err, result)
})
//函数讲解
steem.broadcast.customJson(
wif, //密钥
requiredAuths, // Required_auths
requiredPostingAuths, // 作者
id, // Id
json, //json内容
function(err, result) {
console.log(err, result)
}
)
eg:
let wif = '5dddfffffff'
let author = 'lemooljiang'
let id = 'hello world'
let json = {
"title": '好好的一天',
"author": author,
"body": '有你的一天真好啊!',
"created": new Date().toISOString().split('.')[0],
}
//发布到steem上
this.steem.broadcast.customJson(wif, [], [author], id, JSON.stringify(json), function(err, result) {
console.log(865, err, result)
})
//查找customJson只能使用帐户历史的方法,从中过滤出想要的数据。
searchjson(){
let account = "lemooljiang"
this.steem.api.getAccountHistory(account, -1, 20, function(err, result) {
result.forEach(item => {
//判断是不是custom_json
if(item[1].op[0] == "custom_json"){
console.log(111, item)
if(item[1].op[1].id == "hello world"){
//查看json的值
console.log(122, item[1].op[1].json)
}
}
})
})
}
//帐户历史的数据结构
//item[1].op[0]:"custom_json"
//item[1].op[1]:就是json内容
0: 113
1:
block: 37989844
op: Array(2)
0: "custom_json"
1:
id: "hello world"
json: "{"title":"好好的一天","author":"lemooljiang","body":"有你的一天真好啊!","created":"2019-11-08T08:12:17"}"
required_auths: []
required_posting_auths: ["lemooljiang"]
RE: SteemJS中文手册