Browser Wallet

For connecting, queries and performs wallet functions in accordance to CIP-30.

These wallets APIs are in accordance to CIP-30, which defines the API for dApps to communicate with the user's wallet. Additional utility functions provided for developers that are useful for building dApps.

In this section, you can connect wallet and try APIs for dApps to communicate with your wallet. To start, import BrowserWallet:

// import BrowserWallet
import { BrowserWallet } from '@meshsdk/core';

// connect to a wallet
const wallet = await BrowserWallet.enable('eternl');

// get assets in wallet
const assets = await wallet.getAssets();

Get Installed Wallets

Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:

  • A name is provided to display wallet's name on the user interface.
  • A version is provided to display wallet's version on the user interface.
  • An icon is provided to display wallet's icon on the user interface.

Example:

[
  {
    "name": "eternl",
    "icon": "data:image/png;base64,ICONBASE64HERE=",
    "version": "0.1.0"
  }
]
Get Installed Wallets

Get a list of wallets on user's device

BrowserWallet.getInstalledWallets();

Connect Wallet

This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.

Query BrowserWallet.getInstalledWallets() to get a list of available wallets, then provide the wallet name for which wallet the user would like to connect with.

Connect Wallet

Connect to a CIP30 compatible wallet

const wallet = await BrowserWallet.enable('eternl');
No wallets installed

Get Balance

Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:

  • A unit is provided to display asset's name on the user interface.
  • A quantity is provided to display asset's quantity on the user interface.

Example:

[
  {
    "unit": "lovelace",
    "quantity": "796105407"
  },
  {
    "unit": "0f5560dbc05282e05507aedb02d823d9d9f0e583cce579b81f9d1cd8",
    "quantity": "1"
  },
  {
    "unit": "9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d4d657368546f6b656e",
    "quantity": "2"
  },
]
Get Balance

Get all assets in the connected wallet

const balance = await wallet.getBalance();
No wallets installed

Get Change Address

Returns an address owned by the wallet that should be used as a change address to return leftover assets during transaction creation back to the connected wallet.

Get Change Address

Get address that should be used for transaction's change

const changeAddress = await wallet.getChangeAddress();
No wallets installed

Get Collateral

This function shall return a list of one or more UTXOs (unspent transaction outputs) controlled by the wallet that are required to reach AT LEAST the combined ADA value target specified in amount AND the best suitable to be used as collateral inputs for transactions with plutus script inputs (pure ADA-only UTXOs).

If this cannot be attained, an error message with an explanation of the blocking problem shall be returned. NOTE: wallets are free to return UTXOs that add up to a greater total ADA value than requested in the amount parameter, but wallets must never return any result where UTXOs would sum up to a smaller total ADA value, instead in a case like that an error message must be returned.

Example of a response returned by this endpoint:

[
  {
    "input": {
      "outputIndex": 1,
      "txHash": "ff8d1e97c60989b4f...02ee937595ad741ff597af1"
    },
    "output": {
      "address": "addr_test1qzm...z0fr8c3grjmysm5e6yx",
      "amount": [ { "unit": "lovelace", "quantity": "5000000" } ]
    }
  }
]
Get Collateral

Get list of UTXOs that used as collateral inputs for transactions with plutus script inputs

const collateralUtxos = await wallet.getCollateral();
No wallets installed

Get Network ID

Returns the network ID of the currently connected account. 0 is testnet and 1 is mainnet but other networks can possibly be returned by wallets. Those other network ID values are not governed by CIP-30. This result will stay the same unless the connected account has changed.

Get Network ID

Get currently connected network

const networkId = await wallet.getNetworkId();
No wallets installed

Get Reward Addresses

Returns a list of reward addresses owned by the wallet. A reward address is a stake address that is used to receive rewards from staking, generally starts from `stake` prefix. Example:

[
  "stake_test1uzx0ksy9f4qnj2mzfdncqyjy84sszh64w43853nug5pedjgytgke9"
]
Get Reward Addresses

Get stake addresses

const rewardAddresses = await wallet.getRewardAddresses();
No wallets installed

Get Unused Addresses

Returns a list of unused addresses controlled by the wallet. For example:

[
  "addr_test1qzk9x08mtre4jp8f7j8zu8802...r8c3grjmys7fl22c",
  "addr_test1qrmf35xyw2petfr0e0p4at0r7...8sc3grjmysm73dk8",
  "addr_test1qq6ts58hdaasd2q78fdjj0arm...i8c3grjmys85k8mf",
]
Get Unused Addresses

Get addresses that are unused

const unusedAddresses = await wallet.getUnusedAddresses();
No wallets installed

Get Used Addresses

Returns a list of used addresses controlled by the wallet. For example:

[
  "addr_test1qzk9x08mtre4jp8f7j8zu8802...r8c3grjmys7fl88a",
  "addr_test1qrmf35xyw2petfr0e0p4at0r7...8sc3grjmysm76gt3",
  "addr_test1qq6ts58hdaasd2q78fdjj0arm...i8c3grjmys85dn39",
]
Get Used Addresses

Get addresses that are used

const usedAddresses = await wallet.getUsedAddresses();
No wallets installed

Get UTXOs

Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet. For example:

[
  {
    "input": {
      "outputIndex": 0,
      "txHash": "16dcbb1f93b4f9d5e...9106c7b121463c210ba"
    },
    "output": {
      "address": "addr_test1qzag7whju08xwrq...z0fr8c3grjmysgaw9y8",
      "amount": [
        {
          "unit": "lovelace",
          "quantity": "1314550"
        },
        {
          "unit": "f05c91a850...3d824d657368546f6b656e3032",
          "quantity": "1"
        }
      ]
    }
  }
]
Get UTXOs

Get UTXOs of the connected wallet

const utxos = await wallet.getUtxos();
No wallets installed

Sign Data

This endpoint utilizes the CIP-8 - Message Signing to sign arbitrary data, to verify the data was signed by the owner of the private key.

Here, we get the first wallet's address with wallet.getUsedAddresses(), alternativelly you can use reward addresses (getRewardAddresses()) too. It's really up to you as the developer which address you want to use in your application.

Example of a response from the endpoint:

{
  "signature": "845846a2012...f9119a18e8977d436385cecb08",
  "key": "a4010103272006215...b81a7f6ed4fa29cc7b33186c"
}

Continue reading this guide to learn how to verify the signature.

Sign Data

Use connected wallet to sign a payload

const addresses = await wallet.getUsedAddresses();
const signature = await wallet.signData(addresses[0], 'mesh');
No wallets installed

Sign Transaction

Requests user to sign the provided transaction (tx). The wallet should ask the user for permission, and if given, try to sign the supplied body and return a signed transaction. partialSign should be true if the transaction provided requires multiple signatures.

Sign Transaction

Use connected wallet to sign a transaction

const signedTx = await wallet.signTx(tx, partialSign?);

Check out Transaction to learn more on how to use this API.

Submit Transaction

As wallets should already have this ability to submit transaction, we allow dApps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the dApp to track. The wallet can return error messages or failure if there was an error in sending it.

Submit Transaction

Use connected wallet to submit a transaction

const txHash = await wallet.submitTx(signedTx);

Check out Transaction to learn more on how to use this API.

Get Assets

Returns a list of assets in wallet excluding lovelace, example:

[
  {
    "unit": "1207329a668cf5c42b80a220a8c85d5e82ac0b6f5ecedda4c07a8acc4d657368486f6e6f72546f6b656e2d3530343935",
    "policyId": "1207329a668cf5c42b80a220a8c85d5e82ac0b6f5ecedda4c07a8acc",
    "assetName": "Mesh Token Of Appreciation",
    "fingerprint": "asset1dw74h0w0meqg9cxkc9sezp8zqcxu8nl93fzfpz",
    "quantity": "1"
  }
  {
    "unit": "9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d4d657368546f6b656e",
    "policyId": "9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d",
    "assetName": "MeshToken",
    "fingerprint": "asset177e7535dclmkkph8ewt9fsghllkwmpspa3n98p",
    "quantity": "10"
  }
]
Get Assets

Get assets in the connected wallet

const assets = await wallet.getAssets();
No wallets installed

Get Lovelace

Return the lovelace balance in wallet. 1 ADA = 1000000 lovelace.

Get Lovelace

Get amount of ADA in connected wallet

const lovelace = await wallet.getLovelace();
No wallets installed

Get Policy IDs

Return a list of assets' policy ID. An example response would be:

[
  "0f5560dbc05282e05507aedb02d823d9d9f0e583cce579b81f9d1cd8",
  "5bed9e89299c69d9a54bbc82d88aa5a86698b2b7b9d0ed030fc4b0ff",
  "9c8e9da7f81e3ca90485f32ebefc98137c8ac260a072a00c4aaf142d",
]
Get Policy IDs

Get a list of policy IDs from all assets in wallet

const policyIds = await wallet.getPolicyIds();
No wallets installed

Get a Collection of Assets

Returns a list of assets from a policy ID. If no assets in wallet belongs to the policy ID, an empty list is returned. Query for a list of assets' policy ID with wallet.getPolicyIds().

Get a Collection of Assets

Get a list of assets belonging to the policy ID

const assets = await wallet.getPolicyIdAssets('64af286e2ad0df4de2e7de15f8ff5b3d27faecf4ab2757056d860a42');
No wallets installed