Skip to main content
This page demonstrates various transfer operations on the Hive blockchain, including simple transfers, encrypted memos, and savings operations.

Simple HIVE Transfer

The most basic transfer operation moves HIVE from one account to another.
import { Transaction, PrivateKey } from 'hive-tx'

async function transferHive() {
  const tx = new Transaction()
  
  await tx.addOperation('transfer', {
    from: 'sender',
    to: 'receiver',
    amount: '1.000 HIVE',
    memo: 'Thanks for your help!'
  })
  
  const key = PrivateKey.from('your-active-key')
  tx.sign(key)
  
  const result = await tx.broadcast()
  console.log('Transfer successful!', result.result.tx_id)
}

TransferOperation Type

All transfer operations use the following structure:
interface TransferOperation {
  from: string        // Sender's account name
  to: string          // Recipient's account name
  amount: string      // Amount with 3 decimal places and asset symbol
  memo: string        // Transfer memo (can be encrypted)
}

HBD Transfer

Transferring HBD (Hive Backed Dollars) uses the same operation type.
import { Transaction, PrivateKey } from 'hive-tx'

async function transferHBD() {
  const tx = new Transaction()
  
  await tx.addOperation('transfer', {
    from: 'sender',
    to: 'receiver',
    amount: '10.000 HBD',
    memo: 'Payment for services'
  })
  
  const key = PrivateKey.from('your-active-key')
  tx.sign(key)
  
  const result = await tx.broadcast()
  console.log('HBD transfer successful!', result.result.tx_id)
}

Transfer with Encrypted Memo

Encrypt sensitive messages in transfers using memo encryption.
import { Transaction, PrivateKey, PublicKey, Memo } from 'hive-tx'

async function transferWithEncryptedMemo() {
  // Encrypt the memo first
  const senderMemoKey = PrivateKey.from('5J...sender-memo-key')
  const recipientPublicMemoKey = 'STM...recipient-public-memo-key'
  
  // Messages must start with '#' to be encrypted
  const encryptedMemo = Memo.encode(
    senderMemoKey,
    recipientPublicMemoKey,
    '#Confidential payment details'
  )
  
  // Create transaction with encrypted memo
  const tx = new Transaction()
  
  await tx.addOperation('transfer', {
    from: 'sender',
    to: 'receiver',
    amount: '5.000 HIVE',
    memo: encryptedMemo
  })
  
  // Sign with active key (NOT memo key)
  const activeKey = PrivateKey.from('your-active-key')
  tx.sign(activeKey)
  
  const result = await tx.broadcast()
  console.log('Encrypted transfer successful!', result.result.tx_id)
}

Decrypting a Received Memo

import { Memo, PrivateKey } from 'hive-tx'

function decryptMemo() {
  const recipientMemoKey = PrivateKey.from('5J...recipient-memo-key')
  const encryptedMemo = '#...encrypted-string-from-blockchain'
  
  const decryptedMemo = Memo.decode(recipientMemoKey, encryptedMemo)
  console.log('Decrypted message:', decryptedMemo)
  // Output: '#Confidential payment details'
}

Transfer to Savings

Move funds to your savings account for added security. Savings withdrawals have a 3-day waiting period.
import { Transaction, PrivateKey } from 'hive-tx'

async function transferToSavings() {
  const tx = new Transaction()
  
  await tx.addOperation('transfer_to_savings', {
    from: 'myaccount',
    to: 'myaccount',      // Can transfer to own or another account
    amount: '100.000 HIVE',
    memo: 'Moving to savings'
  })
  
  const key = PrivateKey.from('your-active-key')
  tx.sign(key)
  
  const result = await tx.broadcast()
  console.log('Transfer to savings successful!', result.result.tx_id)
}

TransferToSavingsOperation Type

interface TransferToSavingsOperation {
  from: string        // Account sending funds
  to: string          // Account receiving in savings
  amount: string      // Amount with asset symbol
  memo: string        // Transfer memo
}

Transfer from Savings

Withdraw funds from savings. The funds will be available after a 3-day waiting period.
import { Transaction, PrivateKey } from 'hive-tx'

async function transferFromSavings() {
  const tx = new Transaction()
  
  await tx.addOperation('transfer_from_savings', {
    from: 'myaccount',
    request_id: 1,          // Unique ID for this withdrawal request
    to: 'myaccount',        // Destination account
    amount: '50.000 HIVE',
    memo: 'Withdrawing from savings'
  })
  
  const key = PrivateKey.from('your-active-key')
  tx.sign(key)
  
  const result = await tx.broadcast()
  console.log('Withdrawal initiated!', result.result.tx_id)
  console.log('Funds will be available in 3 days')
}

TransferFromSavingsOperation Type

interface TransferFromSavingsOperation {
  from: string        // Account withdrawing from savings
  request_id: number  // Unique request ID (must be unique per account)
  to: string          // Destination account
  amount: string      // Amount with asset symbol
  memo: string        // Transfer memo
}

Cancel Savings Withdrawal

Cancel a pending withdrawal from savings before the 3-day period expires.
import { Transaction, PrivateKey } from 'hive-tx'

async function cancelSavingsWithdrawal() {
  const tx = new Transaction()
  
  await tx.addOperation('cancel_transfer_from_savings', {
    from: 'myaccount',
    request_id: 1       // The request ID to cancel
  })
  
  const key = PrivateKey.from('your-active-key')
  tx.sign(key)
  
  const result = await tx.broadcast()
  console.log('Withdrawal cancelled!', result.result.tx_id)
}

Multiple Transfers in One Transaction

You can batch multiple transfer operations in a single transaction for efficiency.
import { Transaction, PrivateKey } from 'hive-tx'

async function multipleTransfers() {
  const tx = new Transaction()
  
  // Add multiple transfer operations
  await tx.addOperation('transfer', {
    from: 'sender',
    to: 'alice',
    amount: '1.000 HIVE',
    memo: 'Payment 1'
  })
  
  await tx.addOperation('transfer', {
    from: 'sender',
    to: 'bob',
    amount: '2.000 HIVE',
    memo: 'Payment 2'
  })
  
  await tx.addOperation('transfer', {
    from: 'sender',
    to: 'charlie',
    amount: '3.000 HBD',
    memo: 'Payment 3'
  })
  
  const key = PrivateKey.from('your-active-key')
  tx.sign(key)
  
  const result = await tx.broadcast()
  console.log('All transfers successful!', result.result.tx_id)
}

Important Notes

  • All transfer amounts must include exactly 3 decimal places (e.g., '1.000 HIVE')
  • Use active key to sign transfer operations
  • Encrypted memos require the memo key for encryption/decryption
  • Savings withdrawals have a mandatory 3-day waiting period
  • Request IDs for savings operations must be unique per account
For encrypted memos, only the sender and recipient with the corresponding memo keys can decrypt the message.

Build docs developers (and LLMs) love