gn-provider 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +146 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # GN Provider for sCrypt
2
+
3
+ A custom BSV provider for sCrypt contracts using the WhatsOnChain API. This package provides seamless integration with the Bitcoin SV blockchain through the popular WhatsOnChain service.
4
+
5
+ ## Prerequisites
6
+
7
+ Before using GN Provider, you need to have sCrypt installed in your project. The recommended version is **scrypt-ts v1.3.5** or higher.
8
+
9
+ To check your current sCrypt version:
10
+ ```bash
11
+ npm list scrypt-ts
12
+ ```
13
+
14
+ To install/update sCrypt:
15
+ ```bash
16
+ npm install scrypt-ts@latest
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ Install GN Provider using npm:
22
+
23
+ ```bash
24
+ npm install gn-provider
25
+ ```
26
+
27
+ During installation, the package will automatically:
28
+ 1. Build the provider files
29
+ 2. Copy them to the sCrypt providers directory
30
+ 3. Make them available for import within your sCrypt projects
31
+
32
+ ## Usage
33
+
34
+ ### Basic Setup
35
+
36
+ ```typescript
37
+ import { GNProvider } from 'scrypt-ts/dist/bsv/providers/gn-provider';
38
+ import * as bsv from 'bsv';
39
+
40
+ // Initialize provider (mainnet or testnet)
41
+ const provider = new GNProvider(bsv.Networks.mainnet);
42
+
43
+ // Connect to the provider
44
+ await provider.connect();
45
+
46
+ // Check connection status
47
+ console.log('Connected:', provider.isConnected());
48
+ ```
49
+
50
+ ### Using with sCrypt Contracts
51
+
52
+ ```typescript
53
+ import { GNProvider } from 'scrypt-ts';
54
+ import * as bsv from 'bsv';
55
+ import { MyContract } from './src/contracts/myContract';
56
+
57
+ async function main() {
58
+ // 1. Initialize provider
59
+ const provider = new GNProvider(bsv.Networks.testnet);
60
+ await provider.connect();
61
+
62
+ // 2. Load your contract artifact
63
+ await MyContract.loadArtifact();
64
+
65
+ // 3. Create contract instance
66
+ const instance = new MyContract();
67
+
68
+ // 4. Connect contract to provider
69
+ instance.connect(provider);
70
+
71
+ // 5. Deploy contract
72
+ const deployTx = await instance.deploy(100); // Deploy with initial satoshis
73
+ console.log('Contract deployed:', deployTx.id);
74
+
75
+ // 6. Call contract method
76
+ const { tx: callTx } = await instance.methods.myMethod(...parameters);
77
+ console.log('Method executed:', callTx.id);
78
+ }
79
+
80
+ main().catch(console.error);
81
+ ```
82
+
83
+ ### Advanced Configuration
84
+
85
+ ```typescript
86
+ // With API key for enhanced rate limits
87
+ const provider = new GNProvider(
88
+ bsv.Networks.mainnet,
89
+ 'your-woc-api-key-here'
90
+ );
91
+
92
+ // Set custom timeout (milliseconds)
93
+ provider.connect().timeout(5000);
94
+
95
+ // Handle connection events
96
+ provider.on('connected', (status) => {
97
+ console.log('Connection status changed:', status);
98
+ });
99
+
100
+ provider.on('networkChange', (network) => {
101
+ console.log('Network changed to:', network.name);
102
+ });
103
+ ```
104
+
105
+ ## API Reference
106
+
107
+ ### `new GNProvider(network: bsv.Networks.Network, apiKey?: string)`
108
+ Creates a new provider instance.
109
+ - `network`: BSV network (mainnet or testnet)
110
+ - `apiKey`: Optional WhatsOnChain API key for higher rate limits
111
+
112
+ ### Methods
113
+ | Method | Description |
114
+ |--------|-------------|
115
+ | `connect(): Promise<this>` | Connects to the provider |
116
+ | `isConnected(): boolean` | Checks connection status |
117
+ | `sendRawTransaction(rawTxHex: string): Promise<string>` | Sends raw transaction |
118
+ | `listUnspent(address: string): Promise<UTXO[]>` | Lists UTXOs for an address |
119
+ | `getBalance(address: string): Promise<{confirmed: number, unconfirmed: number}>` | Gets address balance |
120
+ | `getTransaction(txHash: string): Promise<Transaction>` | Retrieves transaction details |
121
+ | `getFeePerKb(): Promise<number>` | Estimates current fee rate |
122
+
123
+ ## Features
124
+
125
+ - **Seamless sCrypt integration**: Automatically installs into sCrypt's provider directory
126
+ - **Real-time connection monitoring**: Event-based connection status updates
127
+ - **Smart fee estimation**: Dynamic fee calculation based on network conditions
128
+ - **Error handling**: Built-in handling of common blockchain errors
129
+ - **TypeScript support**: Full type definitions included
130
+
131
+ ## Troubleshooting
132
+
133
+ If you encounter any issues:
134
+ 1. Verify sCrypt version: `npm list scrypt-ts`
135
+ 2. Check provider installation: Look for `gn-provider.js` in:
136
+ `node_modules/scrypt-ts/dist/bsv/providers/`
137
+ 3. Ensure you're using the correct network (mainnet/testnet)
138
+ 4. Verify your WhatsOnChain API key if using rate-limited operations
139
+
140
+ ## Support
141
+
142
+ For support, bug reports, or feature requests, please open an issue on our [GitHub repository](https://github.com/yourusername/gn-provider).
143
+
144
+ ## License
145
+
146
+ MIT License - see [LICENSE](LICENSE) for details.
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "gn-provider",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "files": [
5
5
  "dist",
6
- "scripts"
6
+ "scripts",
7
+ "README.md"
7
8
  ],
8
9
  "scripts": {
9
10
  "postinstall": "node scripts/install.js"