Skip to main content

Connect to Device

As outlined in the workflow, synchronizing hardware wallet data is a prerequisite for transactions. This article explains how to achieve this using the SDK.

tip

The private key never leaves the hardware wallet.

APIs

MultiAccount

The CryptoMultiAccounts class synchronizes all currency information from the hardware wallet.

function parseMultiAccounts(ur) {
// ...Implementation using gs-ur-js...
}

Parameters

The input parameter ur is a UR object, the output of the URDecoder.

Returns

  • device: the device model name.

  • masterFingerprint: the master fingerprint.

  • keys: the hdkey list.

  • deviceId: the device ID, such as serial numbers.

  • version: The versions.

  • nickName: the wallet account name.

Example

import { parseMultiAccounts } from 'gs-ur-js';

export const MultiAccounts = () => {
const onSucceed = ({ type, cbor }) => {
const multiAccounts = parseMultiAccounts(new UR(Buffer.from(cbor, "hex"), type))
console.log("multiAccounts: ", multiAccounts);
}
const onError = (errorMessage) => {
console.log("error: ", errorMessage);
}

const onCameraStatus = (isCameraReady, error) => {
if (!isCameraReady) {
if (error === "NO_WEBCAM_FOUND") {
console.log("No camera");
} else if (error === "NO_WEBCAM_ACCESS") {
console.log("No camera permission");
}
} else {
console.log("Camera ready");
}
}

const onProgress = (progress) => {
console.log("scan progress: ", progress);
}

return <button onClick={() => <AnimatedQRScanner
handleScan={onSucceed}
handleError={onError}
urTypes={[URType.CryptoMultiAccounts]}
onProgress={onProgress}
videoLoaded={onCameraStatus}
/>
}>Scan GsWallet</button>;
}

If successfully synchronized, you can get wallet information similar to the following content:

{
"device": "GSWALLET",
"masterFingerprint": "27c3831f",
"keys": [
{
"chain": "BTC",
"path": "m/44'/0'/0'",
"publicKey":
"037fb66bad14245d08994f715480b276b73fd33e109f94f589021be6275984c861",
"name": null,
"xfp": "27c3831f",
"chainCode":
"529aa275a0e19c9d3e0fc82381927f9b63f8dbcc8332d1c36250db6ede23aba4",
"extendedPublicKey":
"xpub6CdezvjFXdc95pLVoAAfGEnS9MyVW1d763AMwDzDgr6aj6Fx67kzxmq3ugpSxYLHi6A8yNciYxTjg3sPy5UAJQptMwH2gBm4APtsrT3pd51",
"note": "{\"chain\":[\"Bitcoin\"]}"
},
{
"chain": "BTC",
"path": "m/86'/0'/0'",
"publicKey":
"033cdf0f1101dbf2e4a877b6b779aa59d345cb649c507cef76928e68c00789f83a",
"name": null,
"xfp": "27c3831f",
"chainCode":
"30884b52c8ed7c80eb42d967c62a3e26e5f5ea8c071f2a0bb3c47c7f4604de24",
"extendedPublicKey":
"xpub6DUp5pGy2P3emgQgoes1Qqmf2SmVB4c6tXAqcgDuKfXmNMv7kdnXmmFFcrNmaTbZiN4bNDcrEd6rHxkUE24J3Ehj14CVuGtJQhQhoccgAyZ",
"note": "{\"chain\":[\"Bitcoin\"]}"
},
{
"chain": "ETH",
"path": "m/44'/60'/0'",
"publicKey":
"0377d99c1b2762804f04263aeb470f9a89ece15cbc44977249e5c8e4843126dd27",
"name": null,
"xfp": "27c3831f",
"chainCode":
"b154fee3bf6210099ba1eab2c86fe525fc63abe1c8509abe88aa814574cc6e60",
"extendedPublicKey":
"xpub6DHPziqQ7we7dDW3MfEZN6GiTpj6mXM9SFdtu3gBvVUYm3D1LQHk6Cpf6DfBWojtwqPqHggXKqVqPacAV5R2MHqfJuECXZHFNxekjd4L31N",
"note":
"{\"chain\":[\"Ethereum\", \"BNB\", \"Polygon\", \"zkSync_Era\", \"Base\", \"Fantom\", \"Optimism\", \"Avalanche\", \"Arbitrum\"]}"
},

...

{
"chain": "KAS",
"path": "m/44'/111111'/0'",
"publicKey":
"02075aefa9ab67f17d9eb60854e2d6357859d4df67810315edc0573f61208063a9",
"name": null,
"xfp": "27c3831f",
"chainCode":
"bcb27cad4ccda2b6d0a450d76c65a5c1f8f518b4b531482a7dc9f66474b0ab5b",
"extendedPublicKey":
"xpub6CyUGvaHsKmHKSgyTssHgZUcdymuNxwcVY431h6psm1J57mftsgyhioCErvohw5fRLj5jnbNuQ9J4m6JZ7GkRCmZhS24SrcgTVxK1hAvdFe",
"note": "{\"chain\":[\"Kaspa\"]}"
}
],
"deviceId": "HQ01BI4217DE2973",
"version": "0.0.7",
"nickName": "baby"
}