Skip to content

Commit

Permalink
Merge pull request #87 from secretkeylabs/connect-kit/v0
Browse files Browse the repository at this point in the history
Sats Connect kit
  • Loading branch information
m-aboelenein authored Apr 6, 2024
2 parents 77b430b + 46b0334 commit cd71d22
Show file tree
Hide file tree
Showing 50 changed files with 21,522 additions and 3,478 deletions.
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
# Sats Connect
![logo](/example/public/sats-connect.svg)

Sats connect is a simple javascript library that connects apps to Bitcoin wallets like Xverse to retrieve user wallet addresses and sign transactions (PSBTs).

[Read the docs](https://docs.xverse.app/sats-connect/)
Developers building apps on the Bitcoin ecosystem can use Sats connect to interact with users' wallets:

1. Retrieve users' wallet address(es)

2. Request the signature of arbitrary messages for authentication purposes

3. Request the signature of partially signed Bitcoin transactions (PSBT)

4. Request BTC or Stacks transfers to one or multiple recipients

5. Request Stacks contract interactions and deployments

6. Inscribe sats with arbitrary content for ordinals & BRC-20 use cases

## Quick start

```bash
npm i sats-connect
```

## Usage

### import

```ts
import Wallet from 'sats-connect';
```

### Connect Wallet

```ts
const response = await Wallet.request('getAccounts', {
purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals, AddressPurpose.Stacks],
message: 'Cool app wants to know your addresses!',
});
```

### Request a wallet action

```ts
await Wallet.request('sendTransfer', {...});
```

### Disconnect Wallet

```ts
await Wallet.disconnect();
```

## Documentation

For full documentation, visit [docs.xverse.app](https://docs.xverse.app/sats-connect/).
23 changes: 23 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
54 changes: 54 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Using sats-connect and Xverse to build a dapp
=============================================
This is a simple example of how to use the sats-connect library to build a dapp. The dapp is a simple web application that allows users to send and receive btc and stx using the sats-connect library.

The dapp is built in typescript with Create-React-App.

# Installation and running the dapp
To install the node dependencies for the dapp, run the following command:
```bash
npm i
```

To run the dapp, run the following command:
```bash
npm start
```

The dapp should now be reachable in your browser on http://localhost:3001

# Using sats-connect
[Sats-connect](https://github.com/secretkeylabs/sats-connect) is an open source library which allows you to interact with the Xverse wallet from your dapp. The library exposes a `request` function which you can use to send requests to the Xverse wallet. The `request` function takes a `method` and `params` as arguments. The `method` is the name of the method you want to call in the Xverse wallet and the `params` is an object with the parameters typed specifically for the method.

If using typescript, the methods are typed and will come up in the intellisense of your IDE. Once you have typed a specific method, the params will be typed according to that method and will also come up in the intellisense.

The methods are namespaced according to the functionality they provide, with the exception of Bitcoin methods, which live in the global namespace. For example, to create a Bitcoin send transaction you would call `request('sendTransfer', { ... })`. To create a Stacks send transaction you would call `request('stx_transferStx', { ... })`.

The available Bitcoin methods are:

```
getInfo
getAddresses
signMessage
sendTransfer
signPsbt
```

The Stacks methods are:

```
stx_callContract
stx_deployContract
stx_getAccounts
stx_getAddresses
stx_signMessage
stx_signStructuredMessage
stx_signTransaction
stx_transferStx
```

There are also some more specialised methods exposed by sats connect which have not been migrated to the `request` function yet. One of these can be seen in the main App.tsx file, where we use the `getAddresses` method to get both the Bitcoin and Stacks addresses. However, these methods have a different calling convention using callback functions instead of promises.

# Happy Hacking

And buidl on! 🚀
Loading

0 comments on commit cd71d22

Please sign in to comment.