Skip to content

SDK Reference

getWallet

Initializes a new wallet object. The user should be allowed to make this choice. The usual wallet functions (e.g. signTx, customJson, etc.) can be accessed through the wallet object.

typescript
getWallet = async (walletId: SupportedWallet): Promise<Wallet>

Parameters

  • walletId: ID of the desired wallet. 'peakvault', 'keychain' or 'metamask'.

Returns Wallet

Example

typescript
import { getWallet } from '@peakd/hive-wallet-sdk'

let walletId // Let user choose the wallet

// Get wallet
const wallet = await getWallet(walletId)

// Do something
wallet.signTx(/*...*/)



Hive Wallet API

signTx

Request user confirmation to sign a transaction using the given key.

typescript
signTx = async (
  account: string,
  transaction: Trx,
  keyRole: KeyRole,
): Promise<HiveWalletSignResponse>

Parameters

  • account: account with which the user must sign. Leave empty ('') to let the user decide which account to use.
  • transaction: transaction to sign.
  • keyRole: 'posting', 'active' or 'memo'.

Returns HiveWalletSignResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'
import { Transaction } from 'hive-tx'

const wallet = await getWallet('peakvault')
const account = 'muwave'

// Define the operation to sign
const operation = [
  'custom_json',
  {
    required_auths: [],
    required_posting_auths: [account],
    id: 'hive-wallet-sdk test',
    json: JSON.stringify({
      message: `Test transaction to be signed with ${wallet.name}`
    })
  }
]

// Create a transaction using hive-tx
const tx = new Transaction()
const transaction = await tx.create([operation])

// Request permission to sign
const res = await wallet.signTx(account, transaction, 'posting')

if (res.success) {
  // Sign successful
  const signatures = res.result.signatures
} else {
  // Handle error
  console.error(res.error)
}

broadcast

Request user confirmation to sign and broadcast generic operations using the given key.

typescript
broadcast = async (
  account: string,
  operations: Operation[],
  keyRole: KeyRole,
  displayMessage: DisplayMessage = { title: 'Broadcast transaction' }
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: account with which the user must sign. Leave empty ('') to let the user decide which account to use.
  • operations: operation array that needs to be signed.
  • keyRole: 'posting', 'active' or 'memo'.
  • displayMessage (optional): message explaining the operation to the user.

Returns HiveWalletBroadcastResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const account = 'muwave'
// Define the operation to broadcast
const operation = [
  'custom_json',
  {
    required_auths: [],
    required_posting_auths: [account],
    id: 'hive_wallet_sdk_test',
    json: JSON.stringify({
      message: `Broadcasted from ${wallet.name}`
    })
  }
]

// Request permission to broadcast
const res = await wallet.broadcast(account, [operation], 'posting')

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

customJson

Ask the user to sign and broadcast a custom JSON operation (i.e. a transaction non-native to the Hive blockchain, like a transaction for a second layer like Splinterlands).

typescript
customJson = async (
  account: string,
  id: string,
  keyRole: KeyRole,
  json: { [key: string]: any } | string,
  displayMessage: DisplayMessage = { title: 'Sign custom transaction' }
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: account with which the user must sign. Leave empty ('') to let the user decide which account to use.
  • id: custom JSON id.
  • keyRole: 'posting', 'active' or 'memo'.
  • json: custom JSON body.
  • displayMessage: message explaining the operation to the user.

Returns HiveWalletBroadcastResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

// Let the user choose the account
const account = ''
const key = 'posting'

// Define custom json parameters
const id = 'peak_vault_test'
const body = {
  message: `custom_json sent from ${wallet.name}`
}

// Write a nice display message to explain what the operation does
const displayMessage = {
  title: 'Hive Wallet SDK test',
  message: 'Send a test custom_json using the new Hive Wallet SDK.'
}

// Request Custom JSON
const res = await wallet.customJson(account, id, key, body, displayMessage)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

requestSignBuffer

Ask the user to sign a message with one of their keys. It can be used to securely log in users (see example)

typescript
requestSignBuffer = async (
  account: string,
  keyRole: KeyRole,
  message: string,
  displayMessage: DisplayMessage = {
    title: 'Sign message',
    message:
      'The website wants to verify that you have the required authority on this account (posting, active or memo).'
  }
): Promise<HiveWalletResponse>

Parameters

  • account: account that needs to sign the message.
  • keyRole: 'posting', 'active' or 'memo'.
  • message: message to be signed.
  • displayMessage: message explaining the operation to the user.

Returns HiveWalletResponse

Example

javascript
const res = await wallet.requestSignBuffer('muwave', 'posting', 'Test message')

if (res.success) {
  const signedMessage = res.result
}

transfer

Ask the user to sign and broadcast a transfer operation (i.e. to send money).

typescript
transfer = async (
  from: string,
  to: string,
  amount: number,
  currency: 'HIVE' | 'HBD',
  memo: string = ''
): Promise<HiveWalletBroadcastResponse>

Parameters

  • from: account that should send the transfer. Leave empty ('') to let the user decide which account to use.
  • to: account that should receive the transfer.
  • amount: amount to send.
  • currency: currency, HIVE or HBD.
  • memo: message to send along with the transfer. If it starts with # the memo will be encrypted with the receiver's public memo key.

Returns HiveWalletBroadcastResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const from = 'muwave'
const to = 'spiderman'
const amount = 100
const currency = 'HIVE'
const memo = 'Pizza time!'

// Request transfer
const res = await wallet.transfer(from, to, amount, currency, memo)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

recurrentTransfer

Ask the user to sign and broadcast a recurrent transfer operation, i.e. to send money at fixed time intervals. The first transfer will be sent immediately.

typescript
recurrentTransfer = async (
  from: string,
  to: string,
  amount: number,
  currency: 'HIVE' | 'HBD',
  memo: string,
  recurrence: number,
  executions: number,
  extensions: any = []
): Promise<HiveWalletBroadcastResponse>

Parameters

  • from: account that should send the transfer. Leave empty ('') to let the user decide which account to use.
  • to: account that should receive the transfer.
  • amount: amount to send.
  • currency: currency, HIVE or HBD.
  • memo: message to send along with the transfer. If it starts with # the memo will be encrypted with the receiver's public memo key.
  • recurrence: time interval (in hours) after which the next transfer is sent. The minimum is 24h.
  • executions: the number of times the transfer will be executed.

Returns HiveWalletBroadcastResponse

Example

Assume @muwave hired @spiderman to protect the neighborhood. In order to help the superhero, @muwave decides to send him a weekly allowance of 100 HIVE using the Hive Blockchain.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const from = 'muwave'
const to = 'spiderman'
const amount = 100
const currency = 'HIVE'
const memo = 'Thank you Spiderman!'
const recurrence = 24 * 7 // hours in a week
const executions = 10 // send a total of 10 payments

// Request recurrent transfer
const res = await wallet.recurrentTransfer(from, to, amount, currency, memo, recurrence, executions)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

connect

Returns the list of accounts available in the wallet. Currently this function is not available on Keychain.

typescript
connect = async (): Promise<HiveWalletResponse>

Returns HiveWalletResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const res = await wallet.connect()

if (res.success) {
  // Get accounts list
  const accounts = res.result
}

decode

Ask the user to decode a message (secret) with one of their private keys. The message must have been encoded using the corresponding public key.

typescript
decode = async (
  account: string,
  secret: string,
  keyRole: KeyRole = 'memo'
): Promise<HiveWalletResponse>

Parameters

  • account: account that should decode the message.
  • secret: message that should be decoded.
  • keyRole (optional): key role used to encode the message.

Returns HiveWalletResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

// Must begin with #
const secret = '#...'

// Decode
const res = await wallet.decode('muwave', secret)

if (!res.success) {
  // Decoded message
  const message = res.result
} else {
  console.error(res.error)
}

encode

Ask the user to convert a message using the sender private memo key and the recipient's public memo key.

typescript
encode = async (
  account: string,
  recipientAccount: string,
  message: string
): Promise<HiveWalletResponse>

Parameters

  • account: account that encodes the message (sender).
  • recipientAccount: account that will be able to decode the message.
  • message: message to be encoded. Must start with #, e.g. '#test' and not 'test'.

Returns HiveWalletResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

// Must begin with #
const message = `#Shhh it's a secret`

// Encode
const res = await wallet.encode('muwave', 'peak.double.sig', message)

if (!res.success) {
  // Encoded message
  const secret = res.result
} else {
  console.error(res.error)
}

post

Ask the user to post a blog-post or a comment.

typescript
post = async (
  account: string,
  title: string,
  body: string,
  parentPermlink: string,
  parentAccount: string,
  json_metadata: PostJsonMetadata,
  permlink: string,
  otherOptions?: PostOtherOptions
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: author of the post or comment. Leave empty ('') to let the user decide which account to use.
  • title: title of the comment/post.
  • body: body of the comment/post.
  • parentPermlink: for comments must be the permlink to the parent post. For posts it represents the main tag or the community.
  • parentAccount: for comments must be the account of the author of the parent post. For posts leave empty ('').
  • json_metadata: metadata, like tags or post format. Try to follow the community rules specified here.
  • permlink: permlink of the post/comment.
  • otherOptions: specify advanced options. Check the docs for more information.

Returns HiveWalletBroadcastResponse

Example - Create a new blog-post

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

// Allow user to choose with which account to post
const account = ''
// Title and body of the blog post
const title = 'Hello World!'
const body =
  '## This is a blog post \
  \
  And this is some text'
// Main tag/community
const parent_perm = 'blog'
// No parent account, since it's not a comment
const parent_account = ''
// Metadata
const json_metadata = {
  format: 'markdown',
  description: 'A blog post',
  tags: ['Blog']
}
// Post permlink
const permlink = 'hello-world'

// Request permission to post
const res = await wallet.post(
  account,
  title,
  body,
  parent_perparent_account,
  json_metadata,
  permlink
)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

vote

Ask the user to sign and broadcast a vote operation (i.e. to vote a post).

typescript
vote = async (
  voter: string,
  permlink: string,
  author: string,
  weight: number
): Promise<HiveWalletBroadcastResponse>

Parameters

  • voter: account that should cast the vote. Leave empty ('') to let the user decide which account to use.
  • permlink: permlink to the post to vote.
  • author: author of the post.
  • weight: vote weight [1-10000].

Returns HiveWalletBroadcastResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const voter = 'muwave'
const permlink = 'announcing-the-development-of-peak-vault'
const author = 'peak.open'
const weight = 10000 // 100%

// Request vote
const res = await wallet.vote(account, permlink, author, weight)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

addAccountAuthority

Ask the user (authorizer) to allow accountToAuthorize to sign transactions on their behalf. See the authorities for a more detailed example.

typescript
addAccountAuthority = async (
  account: string,
  accountToAuthorize: string,
  weight: number,
  keyRole: 'posting' | 'active'
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: authorizer.
  • accountToAuthorize: account to authorize.
  • weight: weight of accountToAuthorize's signature.
  • keyRole: 'posting' or 'active'.

Returns HiveWalletBroadcastResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const authorizer = 'peak.double.sig'
const accountToAuthorize = 'muwave'
const weight = 1
const keyRole = 'posting'

// Request add account authority
const res = await wallet.addAccountAuthority(authorizer, accountToAuthorize, weight, keyRole)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

removeAccountAuthority

Ask the user (authorizer) to remove the authorization given to accountToRemove to sign transactions on their behalf. See the authorities for a more detailed example.

typescript
removeAccountAuthority = async (
  account: string,
  accountToRemove: string,
  keyRole: 'posting' | 'active'
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: authorizer.
  • accountToRemove: account to remove.
  • keyRole: key role of the transactions that accountToRemove will not be able to sign anymore. 'posting' or 'active'.

Returns HiveWalletBroadcastResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const authorizer = 'peak.double.sig'
const accountToRemove = 'muwave'
const keyRole = 'posting'

// Request remove account authority
const res = await wallet.removeAccountAuthority(authorizer, accountToAuthorize, keyRole)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

addKeyAuthority

Ask the user (account) to add keyToAuthorize as one of their public keys. Users holding the relative private key will be able to sign transactions on behalf of the account. See the authorities for a more detailed example.

typescript
addKeyAuthority = async (
  account: string,
  keyToAuthorize: string,
  weight: number,
  keyRole: 'posting' | 'active'
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: authorizer.
  • keyToAuthorize: public key to add.
  • weight: weight of keyToAuthorize's signature.
  • keyRole: key role of keyToAuthorize. 'posting' or 'active'.

Returns HiveWalletBroadcastResponse

Example

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const authorizer = 'peak.double.sig'
const accountToAuthorize = 'STM6KvmmbsWzVdm8Uxs7JHgyhxnJ1aDzgMrhTbkVyJZCLEzPfWzo2'
const weight = 1
const keyRole = 'posting'

// Request add key authority
const res = await wallet.addKeyAuthority(authorizer, keyToAuthorize, weight, keyRole)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

removeKeyAuthority

Ask the user (account) to remove the authorization given to keyToRemove to sign transactions on their behalf. See the authorities for a more detailed example.

typescript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

removeKeyAuthority = async (
  account: string,
  keyToRemove: string,
  keyRole: 'posting' | 'active'
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: authorizer.
  • keyToRemove: public key to remove.
  • keyRole: key role of keyToRemove. 'posting' or 'active'.

Returns HiveWalletBroadcastResponse

Example

javascript
const authorizer = 'peak.double.sig'
const keyToRemove = 'STM6KvmmbsWzVdm8Uxs7JHgyhxnJ1aDzgMrhTbkVyJZCLEzPfWzo2'
const keyRole = 'posting'

// Request remove key authority
const res = await wallet.removeKeyAuthority(authorizer, keyToRemove, keyRole)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

witnessVote

Vote an account as witness. A witness is a block producer, so a person that is trusted by Hive users to sign blocks.

typescript
witnessVote = async (
  account: string,
  witness: string,
  approve: boolean
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: voter. Enter '' to let the user decide which account to use.
  • witness: account to vote.
  • approve: true for positive vote, false for negative vote.

Returns HiveWalletBroadcastResponse

Example

User @muwave trusts @steempeak to sign blocks, so @muwave casts a positive witness vote in favor of @steempeak.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const account = 'muwave'
const witness = 'steempeak'
const approve = true

// Request witness vote
const res = await wallet.witnessVote(account, witness, approve)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

governanceProxy

Allow account @proxy to vote for witnesses and proposals in @account's name.

typescript
governanceProxy = async (account: string, proxy: string): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: account that wants to allow proxy to vote for witnesses and proposals in their place. Enter '' to let the user decide which account to use.
  • proxy: account that should be allowed to vote for witnesses and proposals in @account's name.

Returns HiveWalletBroadcastResponse

Example

User @muwave cannot keep up with all the new project proposals in Hive, but he would like to support cool upcoming projects. He trusts that @asgarth will support the right projects, so @muwave delegates his vote to @asgarth.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const account = 'muwave'
const proxy = 'asgarth'

// Request governance proxy
const res = await wallet.governanceProxy(account, proxy)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

createProposal

Create a new proposal to get funding from the Decentralized Hive Fund.

typescript
createProposal = async (
  account: string,
  fundsReceiver: string,
  dailyPay: number,
  title: string,
  permlink: string,
  start: string,
  end: string,
  extensions: any = []
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: account that should publish the proposal. Enter '' to let the user decide which account to use.
  • fundsReceiver: account that should receive the funds.
  • dailyPay: daily pay in HBD.
  • title: proposal title.
  • permlink: permlink to the hive post published by @account explaining the proposal.
  • start: start date in ISO format.
  • end: end date in ISO format.
  • extensions

Returns HiveWalletBroadcastResponse

Example

User @muwave has a great project idea: a website that allows Hive users to bridge their NFTs to Ethereum. It's a hard projects and he estimates it will require 1 year to build. For this reason @muwave decides to ask for funding from the Decentralized Hive Fund. To do so, he publishes a post on one of Hive's social media platforms, explaining what is the goal of the project and how much money he needs to build it, let's say $30/day. Hive users can decide to vote for the proposal and if it gets enough support @muwave will receive a daily pay that will allow him to build what he promised.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const account = 'muwave'
const fundsReceiver = 'muwave'
const dailyPay = 30
const title = 'Hive-Ethereum NFT bridge'
const premlink = 'permlink-to-the-social-media-post'
const start = '2024-01-25T00:00:00'
const end = '2025-01-25T00:00:00'

// Request create proposal
const res = await wallet.createProposal(
  account,
  fundsReceiver,
  dailyPay,
  title,
  permlink,
  start,
  end
)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

removeProposal

Remove proposals by ID.

typescript
removeProposal = (
  creator: string,
  proposalIds: number[],
  extensions: any = []
): Promise<HiveWalletBroadcastResponse>

Parameters

  • creator: proposal creator.
  • proposalIds: proposal IDs. Can be found next to the proposal name at peakd.com/proposals.
  • extensions

Returns HiveWalletBroadcastResponse

Example

User @muwave created a proposal 6 months ago, but it's not getting enough support, so he decides to remove it.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const creator = 'muwave'
const proposalIds = [5]

// Request remove proposal
const res = await wallet.removeProposal(creator, proposalIds)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

updateProposalVotes

Update proposal votes.

typescript
updateProposalVotes = async (
  voter: string,
  proposalIds: number[],
  approve: boolean,
  extensions: any = []
): Promise<HiveWalletBroadcastResponse>

Parameters

  • voter: voter.
  • proposalIds: proposal IDs.Can be found next to the proposal name at peakd.com/proposals.
  • approve: true to approve the proposals, false to reject them.
  • extensions

Returns HiveWalletBroadcastResponse

Example

User @muwave found a great project he would like to support, so he updates his proposal votes.

javascript
const voter = 'muwave'
const proposalIds = [7]
const approve = true

// Request update proposal votes
const res = await wallet.updateProposalVotes(voter, proposalIds, approve)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

delegation

Sets and overrides the power delegated by delegator to delegatee.

typescript
delegation = async (
  delegator: string,
  delegatee: string,
  amount: number,
  unit: 'HP' | 'VESTS' = 'HP'
): Promise<HiveWalletBroadcastResponse>

Parameters

  • delegator: account that will delegate.
  • delegatee: account that will receive the delegation.
  • amount: amount to be delegated.
  • unit: HP (Hive Power) or VESTS.

Returns HiveWalletBroadcastResponse

Example

User @muwave wants to delegate 10 Hive Power (HP) to @asgarth.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const delegator = 'muwave'
const delegatee = 'asgarth'
const amount = 10
const unit = 'HP'

// Request delegation
const res = await wallet.delegation(delegator, delegatee, amount, unit)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

stake

Stake HIVE to the specified account. Also referred as "power up" because staking increases the user's Hive Power (HP). It's also possible to increase someone else's Hive Power by staking Hive on their account.

typescript
stake = async (
  from: string,
  to: string,
  amount: number
): Promise<HiveWalletBroadcastResponse>

Parameters

  • from: account holding the HIVE to be staked. Enter '' to let the user decide which account to use.
  • to: account to which the HIVE will be staked.
  • amount: amount of HIVE to stake.

Returns HiveWalletBroadcastResponse

Example

User @muwave wants his votes to count more, so he increases his Hive Power (HP). He could also decide to increase another user's voting power (e.g. @asgarth).

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const from = 'muwave'
const to = 'muwave' // (or 'asgarth')
const amount = 1

// Request stake
const res = await wallet.stake(from, to, amount)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

unstake

Unstake HIVE from the account. Also referred as "power down".

typescript
unstake = async (
  account: string,
  amount: number
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: account.
  • amount: amount of HIVE to unstake.

Returns HiveWalletBroadcastResponse

Example

User @muwave wants to unstake 1 HIVE.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const account = 'muwave'
const amount = 1 // HIVE

// Request unstake
const res = await wallet.unstake(account, amount)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

convert

Ask the user to convert HIVE <--> HBD.

typescript
 convert = async (
  account: string,
  amount: number,
  HBD2HIVE: boolean
): Promise<HiveWalletBroadcastResponse>

Parameters

  • account: account that will perform the conversion.
  • amount: amount of currency to convert.
  • HBD2HIVE: if true: HBD --> HIVE, else: HIVE --> HBD.

Returns HiveWalletBroadcastResponse

Example

User @muwave wants to convert 5 HBD into HIVE.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const account = 'muwave'
const amount = 5
const HBD2HIVE = true

// Request conversion
const res = await wallet.convert(account, amount, HBD2HIVE)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

createClaimedAccount

Create a new account that was previously claimed.

typescript
createClaimedAccount = async  (
  creator: string,
  newAccount: string,
  ownerAuthority: Required<Authority>,
  activeAuthority: Required<Authority>,
  postingAuthority: Required<Authority>,
  publicMemoKey: string
): Promise<HiveWalletBroadcastResponse>

Parameters

  • creator: account that claimed the account to be created.
  • newAccount: account to create (claimed).
  • ownerAuthority: owner authority object for the new account.
  • activeAuthority: active authority object for the new account.
  • postingAuthority: posting authority object for the new account.
  • publicMemoKey: public memo key for the new account.

Returns HiveWalletBroadcastResponse

Example

User @muwave already claimed the username @peak.double.sig, now he wants to actually create the account @peak.double.sig.

javascript
import { getWallet } from '@peakd/hive-wallet-sdk'

// Get wallet
const wallet = await getWallet('peakvault')

const creator = 'muwave'
const newAccount = 'peak.double.sig'
const owner = {
  weight_threshold: 1,
  account_auths: [],
  key_auths: [['STM8eALyQwyb2C4XhXJ7eZfjfjfSeNeeZREaxPcJRApie1uwzzcuF', 1]]
}
const active = {
  weight_threshold: 1,
  account_auths: [],
  key_auths: [['STM8eALyQwyb2C4XhXJ7eZfjfjfSeNeeZREaxPcJRApie1uwzzcuF', 1]]
}
const posting = {
  weight_threshold: 1,
  account_auths: [],
  key_auths: [['STM8eALyQwyb2C4XhXJ7eZfjfjfSeNeeZREaxPcJRApie1uwzzcuF', 1]]
}
const memo = 'STM8eALyQwyb2C4XhXJ7eZfjfjfSeNeeZREaxPcJRApie1uwzzcuF'

// Request create claimed account
const res = await wallet.createClaimedAccount(creator, newAccount, owner, acitve, posting, memo)

if (res.success) {
  // Broadcast successful
  const trxId = res.result.trx_id
} else {
  // Handle error
  console.error(res.error)
}

setRpc

Set new RPC node url, by default is https://api.hive.blog. The RPC node is the API node through which the wallet will interface with the Hive blockchain. You can find a list of public nodes and learn more here.

typescript
setRpc = (rpc: string): void

Parameters

rpc: RPC node url.

Returns void

Example

javascript
peakvault.setRpc('hive-api.arcange.eu')

id

Returns the ID of the active wallet.

name

Returns the name of the active wallet.