SteemJs注册的两种方法 / 网络研习社#56
参考steemsnippets | 创建免费用户 | Claiming a discounted ("free") account | 创建用户
这两天在社区中查找了SteemJs用户注册的实现方法,还好,测试了下,也都实现了!Steem在原有的基础上提供了一种新的免费注册的方法(discounted_account),这种新方法可以比较快速地完成新用户注册。
SteemJs注册主要有两种方法:一是create_discounted_account,另一个是accountCreate。create_discounted_account是用消耗RC注册,一个新号需要约10,445,334,023,565 RC
,SP大户才能玩得转。像我的帐户(lemooljiang)一天也只能注册2~3个。accountCreate就是付费注册(3个steem),其它的就没什么限制了。
create_discounted_account
如上图所示。
这个是用dsteem来完成注册功能,有两步,一步是申明帐户(claim_account),使其处于Pending状态;第二步是就是直接注册了(create_discounted_account)。
- 安装和挂载
cnpm install dsteem --save
//main.js
const dsteem = require('dsteem')
const client = new dsteem.Client('https://api.steemit.com')
Vue.prototype.dsteem = dsteem
Vue.prototype.client = client
- 两个注册函数
claim_account() {
const creator = "lemooljiang" //创建帐户的用户名
const active_key = "5Jffffffffff" //创建帐户的资金密钥
return new Promise(resolve => {
const wif = this.dsteem.PrivateKey.fromString(active_key)
const fee = this.dsteem.Asset.from(0, 'STEEM')
const op = [
'claim_account',
{
creator: creator,
extensions: [],
fee: fee
}]
this.client.broadcast.sendOperations([op], wif).then(function (result) {
console.log('11,Included in block: ' + result.block_num)
console.log('222,申明新帐户创建成功!' )
resolve("ok")
}, function (error) {
console.error(error)
console.log('333,申明新帐户创建失败!' )
resolve("err")
})
})
},
create_discounted_account() {
const creator = "lemooljiang" //创建帐户的用户名
const active_key = "5Jofffffffffffff" //创建帐户的资金密钥
const username = this.username //新帐户名
const password = this.password //新帐户的密码
return new Promise(resolve => {
const wif = this.dsteem.PrivateKey.fromString(active_key)
const prefix = this.client.addressPrefix
const ownerKey = this.dsteem.PrivateKey.fromLogin(username, password, 'owner').createPublic(prefix)
let owner = this.dsteem.Authority.from(ownerKey)
const activeKey = this.dsteem.PrivateKey.fromLogin(username, password, 'active').createPublic(prefix)
let active = this.dsteem.Authority.from(activeKey)
const postingKey = this.dsteem.PrivateKey.fromLogin(username, password, 'posting').createPublic(prefix)
let posting = this.dsteem.Authority.from(postingKey)
let memo_key = this.dsteem.PrivateKey.fromLogin(username, password, 'memo').createPublic(prefix)
const metadata = {date: new Date()}
const create_op = [
'create_claimed_account',
{
active,
creator,
extensions: [],
json_metadata: metadata ? JSON.stringify(metadata) : '',
memo_key,
new_account_name: username,
owner,
posting,
}
]
this.client.broadcast.sendOperations([create_op], wif).then(function (result) {
console.log('22, Included in block: ' + result.block_num)
console.log('666,新帐户创建成功!' )
resolve("ok")
}, function (error) {
console.log('444,新帐户创建失败!' )
console.error(error)
resolve("err")
})
})
},
accountCreate
这种方法简单直接,付点小费创建就可以啦。
它主要由steem的两个方法来实现:steem.auth.generateKeys 用于生成4组密钥(owner, active, posting, memo),steem.broadcast.accountCreate 用于创建账号。
npm install steem --save
//main.js
import steem from 'steem'
steem.api.setOptions({ url: 'https://api.steemit.com' })
Vue.prototype.steem= steem
register() {
let newAccountName = "bettyliu" //新帐户名
let newAccountPassword = "FDJUJUJUJU" //新帐户的密码
let publicKeys = this.steem.auth.generateKeys(newAccountName, newAccountPassword, ['owner', 'active', 'posting', 'memo'])
let owner = { weight_threshold: 1, account_auths: [], key_auths: [[publicKeys.owner, 1]] }
let active = { weight_threshold: 1, account_auths: [], key_auths: [[publicKeys.active, 1]] }
let posting = { weight_threshold: 1, account_auths: [], key_auths: [[publicKeys.posting, 1]] }
let memoKey = publicKeys.memo
let creator = "lemooljiang" //创建帐户的用户名
let creatorWif = "5Jffffffffffff" //创建帐户的资金密钥
let fee = "3.000 STEEM" //手续费
let jsonMetadata = ""
this.steem.broadcast.accountCreate(
creatorWif,
fee,
creator,
newAccountName,
owner,
active,
posting,
memoKey,
jsonMetadata,
(err, result) => {
if(err){
console.log(444, '创建失败!', err)
}else{
console.log(666, '创建成功!', result)
}
})
}
!thumbup
恭喜你!您的这篇文章入选 @justyy 今日 (2020-01-08) 榜单 【优秀的文章】, 回复本条评论24小时内领赏,点赞本评论将支持 @dailychina 并增加将来您的奖赏。
@justyy 是CN区的见证人,请支持他,给他投票,或者设置justyy为见证人代理。感谢!@justyy的主要贡献:https://steemyy.com
Congratulations! This post has been selected by @justyy as today's (2020-01-08) 【Good Posts】, Steem On! Reply to this message in 24 hours to get rewards. Upvote this comment to support the @dailychina and increase your future rewards! ^_^
SteemIt 工具、API接口、机器人和教程
SteemIt Tools, Bots, APIs and Tutorial
If you believe what I am doing, please consider a spare vote voting me here, thank you very much indeed.
@justyy - the author of https://SteemYY.com and I have been a Steem Witness for more than a year now.
@tipu curate
Posted using Partiko Android
Upvoted 👌 (Mana: 5/15 - need recharge?)
不明觉厉
先收藏,慢慢学
哈,O婶谦虚啦