---
title: Methods
description: The calls your page makes into a mounted widget, and the two wallet handshakes they answer.
---

Almost everything about the widget is configuration, set before it mounts. A few
things are answers your page gives while the customer is using it: a wallet app
confirming an address on the customer's device, or reporting the transaction it
just sent. Those are methods on the element.

```js
const el = document.querySelector('btcdirect-journey');
el.confirmWalletAddress('bc1q…');
```

## The methods

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `confirmWalletAddress(address)` | void | optional | The customer confirmed this payout address on their device. The order is placed. |
| `cancelWalletAddress()` | void | optional | The customer refused the address, or the device check failed. The customer is back on the form. |
| `confirmSellTransaction(orderId, transactionId)` | Promise<boolean> | optional | Your app sent the crypto for a sell order. Binds its on-chain transaction id to the order. Resolves true when we accepted it, or already had it, and false when it was refused. It never rejects. |
| `cancelSellTransaction()` | void | optional | The customer refused the sell in your app, or it could not be sent. |
| `signOut()` | Promise<void> | optional | Ends the customer's session and drops the widget back to a guest. Does nothing when nobody is signed in. |

The wallet answers are only accepted while the widget is waiting for one, so a
late or repeated call does nothing.

## Confirming a payout address

For an app that holds the customer's keys and wants them to verify the address
on their device before anything is ordered.

1. Set `wallet-confirmation-required="true"`.
2. When the customer confirms the order, the widget dispatches
   `btcdirect:wallet-confirmation-requested` with `{ address, id }` and waits.
3. Show the address on the device, then call `confirmWalletAddress(address)`
   or `cancelWalletAddress()`.

```js
el.addEventListener('btcdirect:wallet-confirmation-requested', async (e) => {
  const ok = await device.verifyAddress(e.detail.address);
  if (ok) el.confirmWalletAddress(e.detail.address);
  else el.cancelWalletAddress();
});
```

## Selling from your app's wallet

For an app that sends the crypto itself, so the customer is not shown an address
to pay to by hand.

1. Set `crypto-deposit="wallet"`, and `source-wallet` to the address the
   customer sells from.
2. When the sell order is placed, the widget dispatches
   `btcdirect:sell-transaction-requested` with what to send and where.
3. Send it, then call `confirmSellTransaction(orderId, transactionId)`; or
   `cancelSellTransaction()` when the customer refuses.

```js
el.addEventListener('btcdirect:sell-transaction-requested', async (e) => {
  const { orderId, currency, amount, walletAddress, destinationTag } = e.detail;
  try {
    const txId = await wallet.send({ currency, amount, to: walletAddress, memo: destinationTag });
    await el.confirmSellTransaction(orderId, txId);
  } catch {
    el.cancelSellTransaction();
  }
});
```

> **These need a customer**
>
> A sell order belongs to a customer, not to your api-key. `confirmSellTransaction`
> needs either `user-identifier` or a customer who signed in inside the widget, and
> resolves `false` without one.
