Magic Eden Wallet Developer Docs
  • ๐Ÿ‘‹Welcome
    • Wallet Introduction
  • ๐Ÿ“™Bitcoin
    • Diving into Bitcoin
    • Detecting the Provider
    • Connecting to the Wallet
    • Signing a Message
    • Signing a Transaction
    • Sending BTC
    • Provider API Methods
    • Provider Events
    • FAQs
  • ๐Ÿ“—Solana
    • Diving Into Solana
    • Solana Wallet Adapter
    • Connect Directly to the ME Solana Provider
    • Signing a Message
    • Sending a Transaction
    • Provider API Methods
    • Provider Events
    • FAQs
  • ๐Ÿ“˜EVM
    • Diving into the EVM
    • Connect Directly to the ME EVM Provider
    • Signing a Message
    • Sending a Transaction
    • Library Integrations
      • Wallet Connect
      • Rainbow Kit
      • Wagmi
    • Provider API Methods
    • Provider Events
    • FAQs
  • โ“Resources
    • Demo Apps
    • Logos and Brand Assets
Powered by GitBook
On this page
  1. Bitcoin

Connecting to the Wallet

PreviousDetecting the ProviderNextSigning a Message

Last updated 10 months ago

Connect Wallet

This function is designed to initiate the connection process to a user's Bitcoin wallet. It leverages the to request a user's payment address (native segwit) and ordinals/runes address (taproot).

It makes use of the getBtcProvider method we defined in .

import { getAddress, AddressPurpose, BitcoinNetworkType } from "sats-connect";

async function connectOrDeselect() {
	await getAddress({
		getProvider: getBtcProvider,
		payload: {
			purposes: [AddressPurpose.Ordinals, AddressPurpose.Payment],
			message: "Address for receiving Ordinals and payments",
			network: {
				type: BitcoinNetworkType.Mainnet,
			},
		},
		onFinish: (response) => {
			console.log("onFinish response, ", response.addresses);
	
			// do some action like updating your app context
			connectionStatus?.setAccounts(response.addresses as unknown as Account[]);
		},
		onCancel: () => {
			alert("Request canceled");
		},
	});
}

Once resolved, the method returns an array of the userโ€™s wallet address objects, defined as:

type address = {
    address: string;
    publicKey: string;
    purpose: "payment" | "ordinals";
}

Where:

address field
Description

address

The userโ€™s connected address

publicKey

A hex string representing the bytes of the public key of the account.

purpose

The purpose of the address:

  • payment is used to manage the userโ€™s bitcoin

  • ordinals is used to manage the userโ€™s ordinals

The getAddresss method returns a that resolves if the user approves the connection request.

๐Ÿ“™
Sats Connect getAddress API
Detecting the Provider
Promise