Skip to main content

Wallets Integration

With Mesh, you can initialize a new wallet with:

Browser Wallet​

Browser Wallet is use for connecting, queries and performs wallet functions in accordance to CIP-30, which defines the API for dApps to communicate with the user's wallet.

To use Browser Wallet is simple, just import BrowserWallet execute the APIs, for example:

// 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();
APIs
Get installed walletsBrowserWallet.getInstalledWallets();
Connect walletconst wallet = await BrowserWallet.enable('eternl');
Get balanceconst balance = await wallet.getBalance();
Get change addressconst changeAddress = await wallet.getChangeAddress();
Get network IDconst networkId = await wallet.getNetworkId();
Get reward addressesconst rewardAddresses = await wallet.getRewardAddresses();
Get used addressesconst usedAddresses = await wallet.getUsedAddresses();
Get unused addressesconst unusedAddresses = await wallet.getUnusedAddresses();
Get UTXOsconst utxos = await wallet.getUtxos();
Sign dataconst addresses = await wallet.getUsedAddresses(); const signature = await wallet.signData(addresses[0], 'mesh');
Sign transactionconst signedTx = await wallet.signTx(tx, partialSign?);
Submit transactionconst txHash = await wallet.submitTx(signedTx);
Get lovelaceconst lovelace = await wallet.getLovelace();
Get assetsconst assets = await wallet.getAssets();
Get policy IDsconst policyIds = await wallet.getPolicyIds();
Get collection of assetsconst assets = await wallet.getPolicyIdAssets('64af2...42');
Get Supported Extensionsawait wallet.getSupportedExtensions('eternl');
Get Extensionsawait wallet.getExtensions();
Get DRep ID Keyawait wallet.getPubDRepKey();
Get Registered Pub Stake Keysawait wallet.getRegisteredPubStakeKeys();

Definitely do check out the Mesh Playground for live demo and full explanation.

Mesh Wallet​

App Wallet is use for building transactions in your applications. You can import App Wallet with:

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

Generate a new wallet​

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

const mnemonic = MeshWallet.brew();

Load with Cardano CLI generated keys​

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

const wallet = new MeshWallet({
networkId: 0,
fetcher: blockchainProvider,
submitter: blockchainProvider,
key: {
type: 'cli',
payment: '5820aaca553a7b95b38b5d9b82a5daa7a27ac8e34f3cf27152a978f4576520dd6503',
stake: '582097c458f19a3111c3b965220b1bef7d548fd75bc140a7f0a4f080e03cce604f0e',
},
});

Load with mnemonic phrases​

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

const wallet = new MeshWallet({
networkId: 0,
fetcher: blockchainProvider,
submitter: blockchainProvider,
key: {
type: 'mnemonic',
words: ["solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution","solution"],
},
});

Load with private keys​

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

const wallet = new MeshWallet({
networkId: 0,
fetcher: blockchainProvider,
submitter: blockchainProvider,
key: {
type: 'root',
bech32: 'xprv1cqa46gk29plgkg98upclnjv5t425fcpl4rgf9mq2txdxuga7jfq5shk7np6l55nj00sl3m4syzna3uwgrwppdm0azgy9d8zahyf32s62klfyhe0ayyxkc7x92nv4s77fa0v25tufk9tnv7x6dgexe9kdz5gpeqgu',
},
});

Read only wallet​

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

const wallet = new MeshWallet({
networkId: 0,
fetcher: blockchainProvider,
submitter: blockchainProvider,
key: {
type: 'address',
address: 'addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9',
},
});

Check out the Mesh Playground for live demo and full explanation.