aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/ark/+page.svelte
blob: c9bd69e04d3b417669e2d17cca5c892a09326940 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script>
  import { bytesToHex, randomBytes } from "@noble/hashes/utils";
  import { Ramps, SingleKey, Wallet } from "@arkade-os/sdk";
  import { onMount } from "svelte";

  let boardingAddress = $state();
  let wallet;

  onMount(async () => {
    // const secret = bytesToHex(randomBytes(32));
    const secret =
      "35fe135be231e9cac13835853ab07c4a11b8b745c575755df53a3bf5dd146ca1";
    const identity = SingleKey.fromHex(secret);

    // create a wallet instance
    wallet = await Wallet.create({
      identity,
      arkServerUrl: "https://mutinynet.arkade.sh",
    });

    // You can receive bitcoin offchain instantly! No inbound liquidity!
    const address = await wallet.getAddress();
    console.log("Ark Address:", address);

    const balance = await wallet.getBalance();
    // total is spendable in settlement
    console.log("Total :", balance.total);
    // available is spendable in offchain transactions
    console.log("Available :", balance.available);

    const vtxos = await wallet.getVtxos();
    console.log("Number of VTXOs:", vtxos.length);

    // Log important information about each VTXO
    vtxos.forEach((vtxo, index) => {
      console.log(`VTXO #${index + 1}:`);
      console.log(`  ID: ${vtxo.txid}:${vtxo.vout}`);
      console.log(`  Amount: ${vtxo.value} sats`);
      console.log(`  Batch ID: ${vtxo.virtualStatus.batchTxID}`);
      console.log(`  Status: ${vtxo.virtualStatus.state}`); // "preconfirmed" | "settled" | "swept" | "spent";
    });

    // Get boarding UTXOs
    const boardingUtxos = await wallet.getBoardingUtxos();
    console.log("Number of boarding UTXOs:", boardingUtxos.length);

    // Log important information about each boarding UTXO
    boardingUtxos.forEach((utxo, index) => {
      console.log(`Boarding UTXO #${index + 1}:`);
      console.log(`  TXID: ${utxo.txid}`);
      console.log(`  Output Index: ${utxo.vout}`);
      console.log(`  Amount: ${utxo.value} sats`);
      console.log(
        `  Status: ${utxo.status.confirmed ? "Confirmed" : "Unconfirmed"}`,
      );
    });

    // Get a boarding address
    boardingAddress = await wallet.getBoardingAddress();
    console.log("Boarding Address:", boardingAddress);
  });

  const board = async () => {
    console.log("BOARDING");
    const commitmentTxid = await new Ramps(wallet).onboard();

    console.log("Commitment transaction ID:", commitmentTxid);
  };
</script>

{boardingAddress}

<button onclick={board}>Board</button>