Skip to content

Commit

Permalink
update core version and test-app
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aboelenein committed Apr 2, 2024
1 parent 99a776e commit a46850c
Show file tree
Hide file tree
Showing 12 changed files with 2,503 additions and 292 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

![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).

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
Expand All @@ -24,8 +22,6 @@ Developers building apps on the Bitcoin ecosystem can use Sats connect to intera
npm i sats-connect
```


## Documentation

For full documentation, visit [docs.xverse.app](https://docs.xverse.app/sats-connect/).

21 changes: 3 additions & 18 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@ This is a simple example of how to use the sats-connect library to build a dapp.

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

# Useful Links
- [sats-connect source code](https://github.com/secretkeylabs/sats-connect)
- [sats-connect v2.0.0 documentation](https://docs.xverse.app/sats-connect-wallet-api-for-bitcoin-and-stacks-1)
- [xverse-web-extension-RC v0.31.0](https://github.com/secretkeylabs/xverse-web-extension/pull/809)
- [xverse-web-extension](https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg)

# Prerequisites
This dapp uses an RC version of sats-connect, which implements the [WBIP standard](https://webbtc.netlify.app/wbips/WBIP000), and requires that an RC version of Xverse wallet is installed.

To install the RC version of Xverse wallet, follow the below instructions:
- Download the latest release candidate from the [RC v0.31.0](https://github.com/secretkeylabs/xverse-web-extension/pull/809) page. The link is in the comment at the top of the page under `Release candidate`. Download the `xverse-web-extension.v0.31.0-rc.X.zip` file.
- Unzip the file into an easily accessible folder
- Open Chrome and go to `chrome://extensions/`
- Enable developer mode by clicking the toggle in the top right corner
- Click the `Load unpacked` button and select the folder where you unzipped the release candidate

Further to this, you will need to have Node.js installed on your machine. You can download it from the [Node.js website](https://nodejs.org/).

# Installation and running the dapp
To install the node dependencies for the dapp, run the following command:
```bash
Expand All @@ -43,6 +25,7 @@ If using typescript, the methods are typed and will 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
Expand All @@ -52,6 +35,7 @@ signPsbt
```

The Stacks methods are:

```
stx_callContract
stx_deployContract
Expand All @@ -66,4 +50,5 @@ 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! 🚀
173 changes: 20 additions & 153 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"sats-connect": "2.1.0-a2cd352",
"sats-connect": "file:..",
"typescript": "^4.9.5"
},
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions example/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
min-height: 100vh;
background-color: #282c34;
color: #aeaeae;
;
font-size: calc(10px + 1vmin);

display: flex;
Expand Down Expand Up @@ -37,7 +36,7 @@
}

.action {
color: #FF4D00;
color: #ff4d00;
}

.networkSelectorButton {
Expand Down
8 changes: 3 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Address, BitcoinNetworkType } from 'sats-connect';
import WalletProvider from 'sats-connect';
import Wallet, { Address, BitcoinNetworkType, AddressPurpose } from 'sats-connect';
import './App.css';
import { AddressDisplay, NetworkSelector, SendBtc, SendStx } from './components';
import { useLocalStorage } from './hooks';
import { AddressPurpose } from '@sats-connect/core';

function App() {
const [network, setNetwork] = useLocalStorage<BitcoinNetworkType>(
Expand All @@ -15,7 +13,7 @@ function App() {
const isConnected = addressInfo.length > 0;

const onConnect = async () => {
const response = await WalletProvider.request('getAccounts', {
const response = await Wallet.request('getAccounts', {
purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals, AddressPurpose.Stacks],
message: 'Cool app wants to know your addresses!',
});
Expand All @@ -26,7 +24,7 @@ function App() {
};

const onDisconnect = () => {
WalletProvider.disconnect();
Wallet.disconnect();
setAddressInfo([]);
};

Expand Down
4 changes: 2 additions & 2 deletions example/src/components/SendBtc/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import WalletProvider, { BitcoinNetworkType, RpcErrorCode } from 'sats-connect';
import Wallet, { BitcoinNetworkType, RpcErrorCode } from 'sats-connect';

type Props = {
network: BitcoinNetworkType;
Expand All @@ -11,7 +11,7 @@ const SendBtc = ({ network }: Props) => {
const [txnId, setTxnId] = useState('');

const onClick = async () => {
const response = await WalletProvider.request('sendTransfer', {
const response = await Wallet.request('sendTransfer', {
recipients: [
{
address: address,
Expand Down
Loading

0 comments on commit a46850c

Please sign in to comment.