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({
  appCenterOrigin: 'https://alpha.hydraone.app',
});
  • appCenterOrigin is the origin of the App Center that embeds your game. The client creates and owns the PostMessageTransport for 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 witnessSet = await client.signTx(unsignedTxCbor, true);
const signedTx = attachWitnessSet(unsignedTxCbor, witnessSet);
const txHash = await client.submitTx(signedTx);

signTx returns the witness set, not a signed transaction. Merge it into the unsigned transaction before submitTx; see attachWitnessSet in Wallet operations.

signTx waits for the player 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 game shuts down. It removes listeners and releases the transport.

Next steps