Skip to main content

Cancel request

cancel is used to stop the SDK request that is still running on a given connectId. It is a good fit for user-initiated aborts, page-cleanup logic, or timeout protection around long-running signing flows.

Calling cancel(connectId) does not physically disconnect the device. It only stops the pending request and emits a window-closing style UI event, such as ui-close_window, so the app can close PIN, passphrase, or confirmation UI in sync.

ukeySdk.cancel(connectId);

Inputs

  • connectId - Required string. The connection identifier of the target device, usually returned by Search devices.

Typical cases

  • The user clicks Cancel and does not want to continue the current flow.
  • A route switch, component unmount, or WebView exit should clean up any pending hardware request.
  • A signing or address-confirmation flow needs timeout protection to avoid hanging forever.

Reference snippet

Manual cancellation

ukeySdk.cancel(connectId);

Cleanup on page unmount

useEffect(() => {
return () => {
ukeySdk.cancel(connectId);
};
}, [connectId]);

Timeout protection for long-running calls

async function signWithTimeout(connectId: string, deviceId: string, params: any, timeoutMs = 60_000) {
const timer = setTimeout(() => {
ukeySdk.cancel(connectId);
}, timeoutMs);

try {
const result = await ukeySdk.evmSignTransaction(connectId, deviceId, params);
clearTimeout(timer);
return result;
} catch (error) {
clearTimeout(timer);
throw error;
}
}

Output

cancel(connectId) itself does not return business data:

undefined;

Typical result of a cancelled request

If an in-flight request is interrupted by cancel, that request usually returns an error structure like this:

{
success: false,
payload: {
error: "User cancelled the action",
code: 801, // ACTION_CANCELLED
},
}

For the full list, see Error codes.

cancel vs physical disconnect

Itemcancel(connectId)Physical disconnect (unplug / BLE drop)
BehaviorStops the pending request while keeping the device connectedBreaks the transport and rejects all pending requests
Connection stateThe device can still be used for the next SDK callThe device must be discovered and connected again
Typical useUser cancellation, timeout protection, page cleanupCable unplugged, BLE out of range, system-level disconnect

Notes

  • The SDK does not expose a separate programmatic disconnect method.
  • If you only want to stop the current request and keep the physical connection alive, use cancel.
  • If no more calls are made afterwards, the session can end naturally; transport cleanup happens automatically when the device disconnects or the page/app closes.