@ecency/wallets
v1.4.35
Published
Ecency wallets
Downloads
1,151
Readme
@ecency/wallets
Utilities for managing Hive blockchain wallets and external cryptocurrency wallets within the Ecency ecosystem.
Features
- Create wallets from BIP39 seed phrases
signDigest– create a signature for an arbitrary digestsignTx– sign a transaction with an optional custom chain IDsignTxAndBroadcast– sign a transaction and immediately broadcast itsignExternalTx– sign transactions for external chains like BTC or ETHsignExternalTxAndBroadcast– sign and broadcast transactions on external networksbuildExternalTx– construct transactions or PSBTs for external chainsencryptMemoWithKeys/decryptMemoWithKeys– encrypt or decrypt memos using explicit keysencryptMemoWithAccounts/decryptMemoWithAccounts– encrypt or decrypt memos by looking up account memo keysuseGetExternalWalletBalanceQuery– retrieve balances for external wallets such as BTC, ETH, BNB, SOL, TRON, TON, or APT through Ecency's private API
Installation
yarn add @ecency/wallets
# or
npm install @ecency/walletsUsage
import {
signDigest,
signTx,
signTxAndBroadcast,
signExternalTx,
signExternalTxAndBroadcast,
buildExternalTx,
buildPsbt,
encryptMemoWithKeys,
encryptMemoWithAccounts,
decryptMemoWithKeys,
decryptMemoWithAccounts,
EcencyWalletCurrency,
useGetExternalWalletBalanceQuery,
} from '@ecency/wallets';
import { Client } from '@hiveio/dhive';
const client = new Client('https://api.hive.blog');
const signature = signDigest('deadbeef', privateWif);
const signedTx = signTx(tx, privateWif, customChainId);
await signTxAndBroadcast(client, tx, privateWif);
const btcBuildParams = { /* inputs, outputs, etc. */ };
const btcPsbt = buildExternalTx(EcencyWalletCurrency.BTC, btcBuildParams);
await signExternalTx(EcencyWalletCurrency.ETH, ethSignParams);
await signExternalTxAndBroadcast(EcencyWalletCurrency.BTC, btcSignParams);
const encrypted = await encryptMemoWithAccounts(client, privateWif, 'alice', '#hello');
const memo = decryptMemoWithKeys(privateWif, encrypted);
// query an external wallet balance (e.g., BTC)
const { data: btcBalance } = useGetExternalWalletBalanceQuery(
EcencyWalletCurrency.BTC,
'1BitcoinAddress...'
);
if (btcBalance) {
// balances are returned in base units (satoshis for BTC, wei for ETH, etc.)
console.log(btcBalance.balanceString, btcBalance.unit);
}