snaps_api

Learn how to connect ZetaLink to your custom frontend dApp

defaultSnapOrigin: npm:zetalink

  • Connect ZetaLink

    • Description: Connects the specified snap with the given parameters, enabling its functionalities within the MetaMask environment.

    • Example Usage:

      const result = await window.ethereum.request({
        method: 'wallet_requestSnaps',
        params: { [snapId]: {} }, // default [snapId] params = {} 
      });

  • derive-btc-wallet

    • Parameters:

      • isMainnet (boolean): To derive Mainnet BTC wallet?

    • Description: Generates a Bitcoin testnet address from the BIP32 public key.

    • Usage:

      const address = await window.ethereum.request({
        method: 'wallet_snap',
        params: {
          snapId: defaultSnapOrigin,
          request: {
            method: 'derive-btc-wallet',
          },
        },
      });
      
      // Returns 
      // "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh" |"tb1qex3zpp07a0ctu8x00ah4mnyess0900a2dklttr" // mainnet || testnet
      

  • get-btc-utxo

    • Parameters: None

    • Description: Fetches unspent transaction outputs (UTXOs) for the connected Bitcoin account.

    • Usage:

      const utxos = await window.ethereum.request({
        method: 'wallet_snap',
        params: {
          snapId: defaultSnapOrigin,
          request: {
            method: 'get-btc-utxo',
          },
        },
      });
      
      // Returns 
      // "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh" |"tb1qex3zpp07a0ctu8x00ah4mnyess0900a2dklttr" // mainnet || testnet

  • get-deposit-fees

    • Parameters: None

    • Description: Fetches unspent transaction outputs (UTXOs) for the connected Bitcoin account.

    • Usage:

      const depositFees = await window.ethereum.request({
        method: 'wallet_snap',
        params: {
          snapId: defaultSnapOrigin,
          request: {
            method: 'get-deposit-fees',
          },
        },
      });
      
      // Returns
      // 945910 (sats as number)
      

  • get-btc-trxs

    • Parameters: None

    • Description: Fetches unspent transaction outputs (UTXOs) for the connected Bitcoin account.

    • Usage:

      const transactions = await window.ethereum.request({
        method: 'wallet_snap',
        params: {
          snapId: defaultSnapOrigin,
          request: {
            method: 'get-btc-trxs',
          },
        },
      });

  • get-balance-and-rate

    • Parameters:

      • address (string): The Zeta or Ethereum address for which the balance is to be retrieved.

    • Description: Retrieves the Zeta balance for the specified address.

    • Usage:

      const address = '0xYourEthereumAddress'; // Replace with actual address
      const balance = await window.ethereum.request({
        method: 'wallet_snap',
        params: {
          snapId: defaultSnapOrigin,
          request: {
            method: 'get-balance-and-rate',
            params: [address],
          },
        },
      });
      
      // Returns 
      /* {
        "zeta": {
          "balances": [
            {
              "denom": "azeta",
              "amount": "2986347517451374218"
            }
          ],
          "pagination": {
            "next_key": null,
            "total": "1"
          }
        },
        "nonZeta": [
          {
            "token": {
              "address": "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891",
              "decimals": "18",
              "name": "BNB-bsc_testnet",
              "symbol": "tBNB",
              "total_supply": "19825202226962956112776",
              "type": "ERC-20"
            },
            "value": "550000000000000"
          }
        ],
        "zetaPrice": 0.480197,
        "btcPrice": 59783
      }
      */

  • transact-btc

    • Parameters:

      • amount (number): The amount of Bitcoin to swap.

      • memo (string): An optional memo to include with the transaction, encoded in hex.

      • isCCTX (boolean): A flag indicating whether to use Bitcoin TSS (Threshold Signature Scheme) for the transaction.

    • Description: Executes a cross-chain swap transaction for Bitcoin.

    • Usage:

      const amount = 0.01; // Amount of Bitcoin to swap
      const customMemo = 'YourMemoHere'; // Optional custom memo
      const isCCTX = true; // isCrossChainTransaction 
      
      const trxHash = await window.ethereum.request({
        method: 'wallet_snap',
        params: {
          snapId: defaultSnapOrigin,
          request: {
            method: 'transact-btc',
            params: [
              amount,
              customMemo.length > 0 ? customMemo : defaultMemo, // defaultMemo is auto-created if customMemo is null
              fees,
            ],
          },
        },
      });
      
      // Returns 
      // "3ca3fe3e8f7f0e69abdf50ab2942b3109f88468601fedd79ea57e3e8491025bd" // transaction hash
      
    • defaultMemo checks if ZRC20 address is passed and automatically considers it a CCTX

  • track-cctx

    • Parameters:

      • transactionHash (string): The hash of the cross-chain transaction to track.

    • Description: Tracks a cross-chain transaction by its hash and retrieves the transaction data.

    • Usage:

      const transactionHash = 'yourTransactionHash'; // Replace with actual hash
      const transactionData = await window.ethereum.request({
        method: 'wallet_snap',
        params: {
          snapId: defaultSnapOrigin,
          request: {
            method: 'track-cctx',
            params: [transactionHash],
          },
        },
      });
      
      // Returns 
      /*
      {
        "CrossChainTx": {
          "creator": "zeta167ns6zwczl9asjs47jwv3uhtkxfjcvx3dgf3ct",
          "index": "0x4607fa7805538dab320466e4bc0530fa9c5ca3686da68cb1822492acf9adeef1",
          "zeta_fees": "0",
          "relayed_message": "102fa443f05200bb74aba1c1f15f442dbef32ffb01d97b1de3619ed2c6beb3860147e30ca8a7dc989170991c20c7c4e0021ef0bd3685876cc3ac5251f0",
          "cctx_status": {
            "status": "OutboundMined",
            "status_message": "Outbound succeeded, mined",
            "lastUpdate_timestamp": "1725546253",
            "isAbortRefunded": false
          },
          "inbound_params": {
            "sender": "tb1qex3zpp07a0ctu8x00ah4mnyess0900a2dklttr",
            "sender_chain_id": "18332",
            "tx_origin": "tb1qex3zpp07a0ctu8x00ah4mnyess0900a2dklttr",
            "coin_type": "Gas",
            "asset": "",
            "amount": "4832",
            "observed_hash": "0e5f0285d0727d4ba5ebf33b1d2eb162959deeea1c665967a2fe3fb4cdf70504",
            "observed_external_height": "2903335",
            "ballot_index": "0x4607fa7805538dab320466e4bc0530fa9c5ca3686da68cb1822492acf9adeef1",
            "finalized_zeta_height": "6647368",
            "tx_finalization_status": "Executed"
          },
          "outbound_params": [
            {
              "receiver": "tb1qex3zpp07a0ctu8x00ah4mnyess0900a2dklttr",
              "receiver_chainId": "7001",
              "coin_type": "Gas",
              "amount": "0",
              "tss_nonce": "0",
              "gas_limit": "0",
              "gas_price": "",
              "gas_priority_fee": "",
              "hash": "0x4b5ea13e790b82edc9cf3db9a5ef11f98edb21d250f6ebb882de0168e10e23d0",
              "ballot_index": "",
              "observed_external_height": "6647368",
              "gas_used": "0",
              "effective_gas_price": "0",
              "effective_gas_limit": "0",
              "tss_pubkey": "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p",
              "tx_finalization_status": "Executed"
            }
          ]
        }
      }
      */

Last updated