RE: RE: SteemJS中文手册
You are viewing a single comment's thread from:

RE: SteemJS中文手册

Words
30
Reading
1 min
Listen
Play
7y

参考steemsnippets
SteemJs注册的两种方法

每个新帐户大约需:10,133,795,853,389 RC.

<b-button variant="outline-primary" @click="claim_account">申明帐户</b-button>
<b-button variant="outline-primary" @click="create_discounted_account">注册新帐户</b-button>

cnpm install dsteem --save
//main.js
const dsteem = require('dsteem')
const client = new dsteem.Client('https://anyx.io')
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")
      })
  })
},