Learn more about Mintlify
Enter your email to receive updates about new features and product releases.
Learn how to transfer HIVE, HBD, and use savings operations
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)
}
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)
}
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)
}
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)
}
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'
}
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)
}
interface TransferToSavingsOperation {
from: string // Account sending funds
to: string // Account receiving in savings
amount: string // Amount with asset symbol
memo: string // Transfer memo
}
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')
}
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
}
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)
}
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)
}
'1.000 HIVE')