Skip to content

Commit 839b199

Browse files
author
0x7u
committed
chore: add readme
1 parent 17cd98e commit 839b199

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

packages/sdk/README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# @forbole/kastle-sdk
2+
3+
A JavaScript library for integrating Kaspa cryptocurrency wallet functionality into web applications.
4+
5+
[![npm version](https://img.shields.io/npm/v/@forbole/kastle-sdk.svg)](https://www.npmjs.com/package/@forbole/kastle-sdk)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7+
8+
## Installation
9+
10+
```bash
11+
npm install @forbole/kastle-sdk
12+
```
13+
14+
## Features
15+
16+
- Connect to and manage Kaspa wallets
17+
- Fetch balances and address information
18+
- Send KAS transactions
19+
- Handle wallet events (network changes, account changes)
20+
- Support for multiple networks (mainnet, testnet)
21+
22+
## Usage
23+
24+
```javascript
25+
import {
26+
connect,
27+
getWalletAddress,
28+
getBalance,
29+
sendKaspa
30+
} from '@forbole/kastle-sdk';
31+
32+
// Connect to the wallet
33+
const isConnected = await connect();
34+
35+
if (isConnected) {
36+
// Get the wallet address
37+
const address = await getWalletAddress();
38+
console.log(`Connected to address: ${address}`);
39+
40+
// Get the wallet balance
41+
const balance = await getBalance();
42+
console.log(`Balance: ${balance} sompi`);
43+
44+
// Send KAS to another address
45+
const txId = await sendKaspa('kaspa:recipient_address', 1000000);
46+
console.log(`Transaction sent with ID: ${txId}`);
47+
}
48+
```
49+
50+
## API Reference
51+
52+
### Wallet Connection
53+
54+
#### `isWalletInstalled()`
55+
Checks if a compatible Kaspa wallet provider is installed.
56+
- Returns: `boolean`
57+
58+
#### `connect(networkId?)`
59+
Connects to the wallet on the specified network.
60+
- Parameters:
61+
- `networkId` (optional): The network to connect to (default: 'mainnet')
62+
- Returns: `Promise<boolean>` - True if connection was successful
63+
64+
#### `disconnect(origin?)`
65+
Disconnects the wallet.
66+
- Parameters:
67+
- `origin` (optional): Origin parameter
68+
- Returns: `Promise<void>`
69+
70+
#### `getNetwork()`
71+
Returns the active Kaspa network.
72+
- Returns: `Promise<NetworkId>` ('mainnet' or 'testnet')
73+
74+
#### `switchNetwork(networkId)`
75+
Switches to a different Kaspa network.
76+
- Parameters:
77+
- `networkId`: The network to switch to
78+
- Returns: `Promise<boolean>` - True if successful
79+
80+
### Wallet Information
81+
82+
#### `getWalletAddress()`
83+
Returns the currently connected wallet address.
84+
- Returns: `Promise<string>`
85+
86+
#### `getPublicKey()`
87+
Retrieves the public key associated with the wallet.
88+
- Returns: `Promise<string>`
89+
90+
#### `getBalance()`
91+
Fetches the current balance of the wallet in sompi.
92+
- Returns: `Promise<number>`
93+
94+
#### `getUtxoAddress(p2shAddress?)`
95+
Retrieves unspent UTXOs for the wallet.
96+
- Parameters:
97+
- `p2shAddress` (optional): Optional p2sh address
98+
- Returns: `Promise<any[]>`
99+
100+
### Transactions
101+
102+
#### `sendKaspa(toAddress, amountSompi, options?)`
103+
Sends Kaspa (KAS) to another address.
104+
- Parameters:
105+
- `toAddress`: Recipient address
106+
- `amountSompi`: Amount to send in sompi
107+
- `options` (optional): Additional options like `priorityFee`
108+
- Returns: `Promise<string>` - Transaction ID
109+
110+
### Event Handling
111+
112+
#### `setEventListeners(eventListeners)`
113+
Registers event listeners for account/network/balance changes.
114+
- Parameters:
115+
- `eventListeners`: Event listener function
116+
117+
#### `removeEventListeners()`
118+
Removes all event listeners.
119+
- Returns: `void`
120+
121+
## Features Under Development
122+
123+
The following features are currently under development and not yet fully implemented:
124+
125+
### ⚠️ `signPskt(txJsonString, submit?, protocol?, protocolAction?, priorityFee?)`
126+
Signs a PSKT transaction for KRC20/KRC721 transfers.
127+
128+
### ⚠️ `doCommitReveal(actionScript, options?)`
129+
Commits and reveals a transaction, used for minting/listing KRC assets.
130+
131+
### ⚠️ `doRevealOnly(options)`
132+
Performs only the reveal phase of a commit-reveal operation.
133+
134+
### ⚠️ `signMessage(msg, type?)`
135+
Signs a message using the wallet's private key and returns the signature.
136+
137+
### ⚠️ `compoundUtxo()`
138+
Compounds wallet UTXOs.
139+
140+
## Requirements
141+
142+
- A compatible Kaspa wallet extension must be installed in the browser
143+
- Web application with JavaScript or TypeScript support
144+
145+
## License
146+
147+
MIT

0 commit comments

Comments
 (0)