Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
  • Loading branch information
janniks committed Oct 18, 2023
1 parent 7725052 commit 0ad8d33
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 324 deletions.
1 change: 0 additions & 1 deletion package-lock.json

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

53 changes: 52 additions & 1 deletion packages/sbtc/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
# `sbtc` 0.1.x (developer-release)

// todo
A helper package for interacting with sBTC from JavaScript/TypeScript.

## Installation

```bash
npm install sbtc
```

## Basic Usage

The package exports two high-level helpers for interacting with sBTC:

- `sbtcDepositHelper` — create a deposit transaction (assuming spendable bitcoin UTXOs, and the sBTC peg address)
- `sbtcWithdrawHelper` — create a withdraw transaction (assuming spendable UTXOs, sBTC balance, a Stacks sBTC-withdraw signature via `sbtcWithdrawMessage`, and the sBTC peg address)

Additionally, there are two API helpers, which make it easier to get all the data needed to create the above transactions:

- `DevEnvHelper` — a helper for interacting with a local development environment [`sbtc/devenv`](https://github.com/stacks-network/sbtc/tree/main/devenv)
- `TestnetHelper` — a helper for interacting with the testnet deployment of the sBTC contract

### `sbtcDepositHelper`

```typescript
import { DevEnvHelper, sbtcDepositHelper } from 'sbtc';

const dev = new DevEnvHelper();

// Transaction building
const tx = await sbtcDepositHelper({
pegAddress: await dev.getSbtcPegAddress(),

stacksAddress: MY_STX_ADDRESS,
amountSats: 1_000, // amount of BTC to deposit, in satoshis

feeRate: await dev.estimateFeeRate('low'),
utxos: await dev.fetchUtxos(MY_BTC_ADDRESS);

bitcoinChangeAddress: MY_BTC_ADDRESS,
});

// Transaction signing and broadcasting
tx.sign(MY_BTC_PRIVATE_KEY);
tx.finalize();

const txid = await dev.broadcastTx(tx);
console.log('txid', txid)

// Or: export as PSBT for signing with a different wallet
const psbtBytes = tx.toPSBT();
```

> **Note:** Here `DevEnvHelper` can be replaced with `TestnetHelper` to interact with the testnet deployment of the sBTC contract.
3 changes: 1 addition & 2 deletions packages/sbtc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sbtc",
"version": "0.1.7",
"version": "0.1.8",
"description": "Library for sBTC.",
"license": "MIT",
"author": "Hiro Systems PBC (https://hiro.so)",
Expand All @@ -27,7 +27,6 @@
"@stacks/common": "^6.7.0",
"@stacks/encryption": "^6.7.0",
"@stacks/transactions": "^6.7.0",
"@stacks/wallet-sdk": "^6.7.0",
"c32check": "^2.0.0",
"micro-packed": "^0.3.2"
},
Expand Down
Loading

0 comments on commit 0ad8d33

Please sign in to comment.