Skip to main content

Get Going

This walkthrough covers how to detect the UKey Wallet Algorand Provider, connect the account, enable the ARC-0001 interface, and work with the Algod/Indexer client to read the network status.

ℹ️

UKey Wallet Algorand Provider supports both traditional interfaces and ARC-0001 compatible interfaces, making it easy to access new and old projects.


Find Provider

// Detect the UKey Wallet Algorand provider
const provider = window.$ukey?.algo;

if (!provider) {
throw new Error("UKey Wallet Algorand provider not detected");
}

// Verify compatibility
console.log("isUKey:", provider.isUKey); // Reference value: true

Connect (legacy API)

const { address } = await provider.connect();
console.log("Connection established:", address);

// Verify connection state
console.log("isConnected:", provider.isConnected);
console.log("Resolved address:", provider.address);

Enable (ARC-0001)

const callResult = await provider.enable({
genesisID: "mainnet-v1.0",
genesisHash: "wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=",
});

console.log("Selected account:", callResult.accounts);
console.log("Network genesis hash:", callResult.genesisHash);

await provider.disconnect();
console.log("Connection closed");

Event Flow

Watch Accounts

provider.on("accountChanged", (address) => {
if (address) {
console.log("Active account changed:", address);
} else {
console.log("Connection closed");
}
});

Listen for connections

provider.on("connect", ({ address }) => {
console.log("Connection established:", address);
});

provider.on("disconnect", () => {
console.log("Connection closed");
});

Works with Algod client

Get the client from Provider

// Retrieve a preconfigured client
const algodClient = await provider.getAlgodv2Client();
const indexerClient = await provider.getIndexerClient();

// Use the client
const status = await algodClient.status().do();
console.log("Reported network status:", status);

Manually set up the client

import algosdk from "algosdk";

const algodClient = new algosdk.Algodv2(
"", // 公共节点一般不需要 Token
"https://mainnet-api.algonode.cloud",
"",
);

const indexerClient = new algosdk.Indexer(
"",
"https://mainnet-idx.algonode.cloud",
"",
);