Quick Start
Sats Connect is a simple javascript library that connects apps to Bitcoin wallets like Xverse to retrieve user wallet addresses and request signing of transactions (PSBTs).
In this quick start guide, we'll go over the basic steps to:
- 1.Retrieve the user's wallet address(es)
- 2.Request signing of a partially signed Bitcoin transaction.
To get started, import sats-connect into your project.
npm install sats-connect
import { getAddress, signTransaction } from 'sats-connect'
To retrieve the user's Bitcoin address, we can use the
getAddress()
function. We provide a purpose
in the request so the correct address is returned by the wallet. Additionally, choose a message to be displayed to the user in the request prompt. You can use this to explain to the user why your app is requesting access to their Bitcoin address.const getAddressOptions = {
payload: {
purposes: ['ordinals', 'payment'],
message: 'Address for receiving Ordinals and payments',
network: {
type:'Mainnet'
},
},
onFinish: (response) => {
console.log(response)
},
onCancel: () => alert('Request canceled'),
}
await getAddress(getAddressOptions);
The user will see an address request prompt in the wallet. Xverse browser extension UI shown for example:

Currently, you can retrieve two types of addresses, the user's Bitcoin payment address and the Ordinals address which is a taproot address.
An example response:
addresses: [
{
address: "tb1pzwa68q3udj0f7g5xtdakgecvf45dvssu66ry7y3at22w7vus20vq3sgw62",
publicKey: "b9907521ddb85e0e6a37622b7c685efbdc8ae53a334928adbd12cf204ad4e717",
purpose: "ordinals",
},
{
address: "2NBfRKCUpafbatj5gV9T82uau3igdSf9BXJ",
publicKey: "02818b7ff740a40f311d002123087053d5d9e0e1546674aedb10e15a5b57fd3985",
purpose: "payment",
}
]
The public keys for each address is also included in the response. You can use this to construct partially signed Bitcoin transactions (PSBT).
To request signing of PSBT, you can use the
signTransaction
function.The PSBT to be signed must be base64 encoded. You can use any Bitcoin library to construct this transaction. See examples using
micro-btc-signer
here: Creating PSBTsconst signPsbtOptions = {
payload: {
network: {
type:'Mainnet'
},
message: 'Sign Transaction',
psbtBase64: `cHNidP8BAJwCAmO+JvQJxhVDDpm3tV5PmPfzvJOSL4GOdjEOpAAAAAAnrAAA==`,
broadcast: false,
inputsToSign: [{
address: "33TKH4kkiFPyTLDNmdNsLggyLeAYre57Qm",
signingIndexes: [1],
}],
},
onFinish: (response) => {
console.log(response.psbtBase64)
alert(response.psbtBase64)
},
onCancel: () => alert('Canceled'),
}
await signTransaction(signPsbtOptions);
You must specify the input index and the address to be signed in the request.
For example:
inputsToSign: [{
address: "bc1pr09enf3yc43cz8qh7xwaasuv3xzlgfttdr3wn0q2dy9frkhrpdtsk05jqq",
signingIndexes: [0]
}, {
address: "33TKH4kkiFPyTLDNmdNsLggyLeAYre57Qm",
signingIndexes: [1,2]
}]
The above parameters will ask the wallet to sign for address
bc1pr09enf3yc43cz8qh7xwaasuv3xzlgfttdr3wn0q2dy9frkhrpdtsk05jqq
at input index 0. And for address 33TKH4kkiFPyTLDNmdNsLggyLeAYre57Qm
at input indexes 1 and 2.You can also optionally specify a signature hash:
inputsToSign: [{
address: "bc1pr09enf3yc43cz8qh7xwaasuv3xzlgfttdr3wn0q2dy9frkhrpdtsk05jqq",
signingIndexes: [0],
sigHash: 131 // SIGHASH_SINGLE | ANYONECANPAY
}]
The user will see a transaction signing request prompt in the wallet. Xverse browser extension UI shown for example:

Depending on your use case, you can request that the PSBT be finalized and broadcasted after the user signs. Otherwise, the signed PSBT will be returned in the response without broadcasting.
If the transaction is broadcasted, you will receive a TXID in the response.
That's it!
Last modified 2mo ago