Docs Getting started
Quick start
Connect to the host, read an address and a balance, and sign your first transaction.
This page gets you from an installed package to a signed transaction. If you have not installed the SDK yet, start with Installation.
1. Create the client
import { WalletBridgeClient, HydraBridgeError } from '@hydraone-sdk/core';
const client = new WalletBridgeClient({
hostOrigin: 'https://alpha.hydraone.app',
});
hostOriginis the origin of the App Center that embeds your app. The client creates and owns thePostMessageTransportfor you.
2. Connect and read
try {
await client.init();
const [address] = await client.getUsedAddresses();
const balance = await client.getBalance();
console.log(`Connected as ${address}, balance:`, balance);
} catch (err) {
if (err instanceof HydraBridgeError) {
console.error(`[${err.code}] ${err.message}`);
}
}
getBalance() returns a list of assets ({ unit, quantity }). The React and Vue helpers read the lovelace for you; see Wallet operations.3. Sign and submit
const signedTx = await client.signTx(unsignedTxCbor, { partialSign: true, mergeWitnesses: true });
const txHash = await client.submitTx(signedTx);
With mergeWitnesses: true, signTx returns the signed transaction. Without it you get the CIP-30 witness set; see Wallet operations.
signTx waits for the user to approve, so it can take a while. Handle a rejection and a timeout as shown in Wallet operations.
4. Clean up
client.destroy();
Call it when the app shuts down. It removes listeners and releases the transport.
Next steps
- Connection lifecycle to understand how
init()chooses a connection. - React and Next.js or Vue and Nuxt to use the framework helpers.
