Wallet operations
All calls below need a connected client. See Connection lifecycle.
Read addresses and balances
const [address] = await client.getUsedAddresses();
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 such as
getUsedAddresses()return exactly what the wallet or host returns. CIP-30 wallets return hex, while a host shell may return bech32.
Other queries: getUtxos, getCollateral, getUnusedAddresses, 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
signTx returns the witness set (hex CBOR of a TransactionWitnessSet), not a signed transaction. This holds for extension and embedded wallets alike, and the host forwards submitTx unchanged, so merge the witness set into the unsigned transaction yourself and submit the result. The SDK does not ship this step; use your Cardano transaction library, for example @emurgo/cardano-serialization-lib-browser:
import { FixedTransaction, TransactionWitnessSet } from '@emurgo/cardano-serialization-lib-browser';
export function attachWitnessSet(unsignedTxCbor: string, witnessSetHex: string): string {
const tx = FixedTransaction.from_hex(unsignedTxCbor);
const vkeys = TransactionWitnessSet.from_hex(witnessSetHex).vkeys();
for (let i = 0; vkeys && i < vkeys.len(); i++) tx.add_vkey_witness(vkeys.get(i));
return tx.to_hex();
}
import { WalletBridgeClient, HydraUserRejectedError, HydraTimeoutError } from '@hydraone-sdk/core';
export async function signAndSubmit(client: WalletBridgeClient, unsignedTxCbor: string) {
try {
const witnessSet = await client.signTx(unsignedTxCbor, true, { timeoutMs: 60_000 });
const signedTx = attachWitnessSet(unsignedTxCbor, witnessSet);
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;
}
}
signTx and submitTx wait for the player, 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.
