Transactions
Hive Keychain
The Keychain API is completely separate from configurations, aliases and environment variables. It takes a raw username and the extension signs with the user's own key.
Open the Keychain playgroundDetect the extension
if (!hive.keychain.isAvailable()) {
// The extension injects asynchronously — re-check shortly after mount.
}Note
window.hive_keychain after page load. Check once on mount and once again after a short delay.Sign in
const result = await hive.keychain.requestSignIn({
username: "alice",
message: "Sign in to my-application: nonce-123456",
authority: "posting",
});
console.log(result.signature);Use an app-generated challenge message, store or verify the returned signature in your own app, and generate a new challenge for each sign-in attempt.
Send a transaction
const result = await hive.keychain.customJson({
username: "alice",
id: "my-application",
action: "claim",
metadata: { rewardId: "123" },
authority: "posting",
message: "Claim reward",
});A rejected popup throws with code KEYCHAIN_REJECTED; a missing extension throws KEYCHAIN_UNAVAILABLE.
Transfers: native and Layer 2
One call covers both layers. "HIVE" / "HBD" is a native Layer 1 transfer; any other symbol is a Hive Engine token and the SDK routes it to Keychain's token transfer request. The memo is carried verbatim in both cases.
// Layer 1
await hive.keychain.requestTransfer({
username: "alice",
to: "treasury",
amount: "1.000",
currency: "HIVE",
memo: JSON.stringify({ action: "buy_pack", metadata: { packs: 1 } }),
});
// Layer 2 — same call, token symbol as currency
await hive.keychain.requestTransfer({
username: "alice",
to: "treasury",
amount: "5",
currency: "SCRAP",
memo: JSON.stringify({ action: "buy_pack", metadata: { packs: 1 } }),
});Hive Engine contract actions via Keychain
await hive.keychainIssuer.token.transfer({
username: "alice",
symbol: "MYTOKEN",
account: "bob",
quantity: "1",
});
await hive.keychainIssuer.nft.transfer({
username: "alice",
account: "bob",
nfts: [{ symbol: "HERO", ids: ["1", "2"] }],
});Compared to backend
| Backend | Hive Keychain | |
|---|---|---|
| Runs in | Server runtime | Browser |
| Account input | Account alias | username |
| Signing key | Environment variable | User wallet |
| Signing | Configured private key | Keychain extension |
| Approval | None — automated | User approves each request |
| Broadcast | hive.rpc | Keychain extension |
| Entry point | hive.issuer | hive.keychain |
These are two separate transaction APIs. Neither one wraps the other, and there is no execution-mode switch between them.
