Wallet operations
All calls below need a connected client. See Connection lifecycle.
Read addresses and balances
const address = await client.getChangeAddress();
const balance = await client.getBalance();
getBalance()returns the balance as a list of assets ({ unit, quantity }, whereunitislovelaceorpolicyId + assetNameHex). The ReactuseWallethook and the VueuseWalletBridgeClientcomposable read its lovelace for you, exactly and as abigint:const { balanceADA, balanceLovelace } = useWallet(); // "1234.56789" and 1234567890n
Outside the hooks, sum the entries whoseunitislovelace.- Address queries (
getChangeAddress,getUsedAddresses,getUnusedAddresses,getRewardAddresses) return bech32 by default. Pass{ format: 'hex' }to get raw CIP-30 hex. Entries the host sends that are not valid addresses are skipped. The hooks'addressis the change address; callclient.getUsedAddresses()when you need the full list. getRewardAddresses()returns the stake addresses (stake1…orstake_test1…).- To convert addresses yourself, use the helpers exported from
@hydraone-sdk/core:formatAddress(address, format),addressToBech32,addressToHex,detectAddressFormat,isValidAddress,isBaseAddressandrewardAddressFromBase.
Other queries: getUtxos, getCollateral, getUsedAddresses, getUnusedAddresses, getRewardAddresses, getChangeAddress, getNetworkId.
getUtxos and getCollateral return decoded Utxo objects ({ input, output }), not CBOR hex. Convert them with your transaction library if it expects CBOR.
Sign and submit
By default signTx returns the witness set (hex CBOR of a TransactionWitnessSet), as CIP-30 does, not a signed transaction. Pass mergeWitnesses: true to get the signed transaction instead, ready for submitTx. The SDK merges the wallet's vkey witnesses without re-serializing the body, so the transaction id does not change. applyWitnessSet(txCbor, witnessSet) does the same step on its own.
With mergeWitnesses: true, if the transaction is not valid CBOR, signTx rejects with ERR_INVALID_PARAMS before the wallet prompt. If the wallet's witness set cannot be merged, it rejects with ERR_INVALID_RESPONSE, and the witness set is kept in err.details.witnessSet so the signature is not lost.
import { WalletBridgeClient, HydraUserRejectedError, HydraTimeoutError } from '@hydraone-sdk/core';
export async function signAndSubmit(client: WalletBridgeClient, unsignedTxCbor: string) {
try {
const signedTx = await client.signTx(unsignedTxCbor, {
partialSign: true,
mergeWitnesses: true,
timeoutMs: 60_000,
});
const txHash = await client.submitTx(signedTx);
return txHash;
} catch (err) {
if (err instanceof HydraUserRejectedError) return null;
if (err instanceof HydraTimeoutError) throw new Error('Wallet did not respond in time');
throw err;
}
}
signData takes a bech32 or hex address. signTx, signData and submitTx wait for the user, so their default timeout is two minutes (signingTimeoutMs). Override it per call with { timeoutMs }.
Next steps
- Errors for every error class and how to recover.
