Connecting to the Wallet
Connect Wallet
This function is designed to initiate the connection process to a user's Bitcoin wallet. It leverages the Sats Connect getAddress API to request a user's payment address (native segwit) and ordinals/runes address (taproot).
It makes use of the getBtcProvider
method we defined in Detecting the Provider.
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");
},
});
}
The getAddresss
method returns a Promise that resolves if the user approves the connection request.

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
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 bitcoinordinals
is used to manage the userโs ordinals
Last updated