viz-js-lib 0.11.0 → 0.12.4
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.
- package/.qoder/docs/spec/viz-dns-nameserver-spec.md +982 -0
- package/.qoder/docs/viz-cpp-node-docs/data-types.md +322 -0
- package/.qoder/docs/viz-cpp-node-docs/index.md +160 -0
- package/.qoder/docs/viz-cpp-node-docs/op-account-market.md +236 -0
- package/.qoder/docs/viz-cpp-node-docs/op-account.md +199 -0
- package/.qoder/docs/viz-cpp-node-docs/op-award.md +162 -0
- package/.qoder/docs/viz-cpp-node-docs/op-committee.md +193 -0
- package/.qoder/docs/viz-cpp-node-docs/op-content.md +157 -0
- package/.qoder/docs/viz-cpp-node-docs/op-escrow.md +224 -0
- package/.qoder/docs/viz-cpp-node-docs/op-invite.md +219 -0
- package/.qoder/docs/viz-cpp-node-docs/op-proposal.md +229 -0
- package/.qoder/docs/viz-cpp-node-docs/op-recovery.md +188 -0
- package/.qoder/docs/viz-cpp-node-docs/op-subscription.md +146 -0
- package/.qoder/docs/viz-cpp-node-docs/op-transfer-vesting.md +224 -0
- package/.qoder/docs/viz-cpp-node-docs/op-witness.md +252 -0
- package/.qoder/docs/viz-cpp-node-docs/plugins.md +887 -0
- package/.qoder/docs/viz-cpp-node-docs/virtual-operations.md +513 -0
- package/.qoder/repowiki/en/content/API Reference/API Reference.md +724 -0
- package/.qoder/repowiki/en/content/API Reference/Configuration Options.md +410 -0
- package/.qoder/repowiki/en/content/API Reference/Core API Methods.md +547 -0
- package/.qoder/repowiki/en/content/API Reference/Streaming APIs.md +380 -0
- package/.qoder/repowiki/en/content/API Reference/Transport Layer.md +341 -0
- package/.qoder/repowiki/en/content/API Reference/VIZ Blockchain Operations Coverage Status.md +427 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Authentication & Cryptography.md +430 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Digital Signatures.md +462 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Key Management.md +456 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Memo Encryption.md +331 -0
- package/.qoder/repowiki/en/content/Authentication & Cryptography/Security Practices.md +488 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Broadcast Transactions.md +432 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Network Broadcasting.md +418 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Operation Construction.md +352 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Preparation.md +353 -0
- package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Signing.md +404 -0
- package/.qoder/repowiki/en/content/Data Serialization/Data Serialization.md +540 -0
- package/.qoder/repowiki/en/content/Data Serialization/Encoding & Decoding.md +463 -0
- package/.qoder/repowiki/en/content/Data Serialization/Object Templates.md +413 -0
- package/.qoder/repowiki/en/content/Data Serialization/Type System.md +514 -0
- package/.qoder/repowiki/en/content/Data Serialization/Validation Rules.md +439 -0
- package/.qoder/repowiki/en/content/Examples & Tutorials.md +485 -0
- package/.qoder/repowiki/en/content/Getting Started.md +345 -0
- package/.qoder/repowiki/en/content/Testing & Development.md +637 -0
- package/.qoder/repowiki/en/content/Utilities & Helpers.md +557 -0
- package/.qoder/repowiki/en/meta/repowiki-metadata.json +1 -0
- package/VIZ-JS-LIB-COVERAGE-STATUS.md +356 -0
- package/config.json +3 -1
- package/dist/statistics.html +1 -1
- package/dist/viz-tests.min.js +32 -42
- package/dist/viz-tests.min.js.gz +0 -0
- package/dist/viz.min.js +8 -18
- package/dist/viz.min.js.gz +0 -0
- package/lib/api/methods.js +24 -0
- package/lib/auth/serializer/src/ChainTypes.js +2 -1
- package/lib/auth/serializer/src/operations.js +35 -2
- package/lib/broadcast/index.js +29 -15
- package/lib/broadcast/operations.js +4 -0
- package/lib/dns.js +658 -0
- package/lib/index.js +3 -1
- package/package.json +3 -2
- package/test/dns.test.js +395 -0
- package/webpack/makeConfig.js +3 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
# Examples & Tutorials
|
|
2
|
+
|
|
3
|
+
<cite>
|
|
4
|
+
**Referenced Files in This Document**
|
|
5
|
+
- [README.md](file://README.md)
|
|
6
|
+
- [package.json](file://package.json)
|
|
7
|
+
- [src/index.js](file://src/index.js)
|
|
8
|
+
- [src/api/index.js](file://src/api/index.js)
|
|
9
|
+
- [src/api/methods.js](file://src/api/methods.js)
|
|
10
|
+
- [src/api/transports/index.js](file://src/api/transports/index.js)
|
|
11
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js)
|
|
12
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js)
|
|
13
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js)
|
|
14
|
+
- [src/broadcast/operations.js](file://src/broadcast/operations.js)
|
|
15
|
+
- [src/auth/index.js](file://src/auth/index.js)
|
|
16
|
+
- [src/formatter.js](file://src/formatter.js)
|
|
17
|
+
- [src/utils.js](file://src/utils.js)
|
|
18
|
+
- [src/config.js](file://src/config.js)
|
|
19
|
+
- [examples/index.html](file://examples/index.html)
|
|
20
|
+
- [examples/stream.html](file://examples/stream.html)
|
|
21
|
+
- [examples/broadcast.html](file://examples/broadcast.html)
|
|
22
|
+
- [examples/server.js](file://examples/server.js)
|
|
23
|
+
- [examples/test-vote.js](file://examples/test-vote.js)
|
|
24
|
+
- [examples/get-post-content.js](file://examples/get-post-content.js)
|
|
25
|
+
</cite>
|
|
26
|
+
|
|
27
|
+
## Table of Contents
|
|
28
|
+
1. [Introduction](#introduction)
|
|
29
|
+
2. [Project Structure](#project-structure)
|
|
30
|
+
3. [Core Components](#core-components)
|
|
31
|
+
4. [Architecture Overview](#architecture-overview)
|
|
32
|
+
5. [Detailed Component Analysis](#detailed-component-analysis)
|
|
33
|
+
6. [Dependency Analysis](#dependency-analysis)
|
|
34
|
+
7. [Performance Considerations](#performance-considerations)
|
|
35
|
+
8. [Troubleshooting Guide](#troubleshooting-guide)
|
|
36
|
+
9. [Conclusion](#conclusion)
|
|
37
|
+
10. [Appendices](#appendices)
|
|
38
|
+
|
|
39
|
+
## Introduction
|
|
40
|
+
This document provides practical, step-by-step examples and tutorials for the VIZ JavaScript library. It covers browser-based and Node.js usage, common scenarios such as account management, voting operations, content creation, and real-time streaming. You will learn how to set up the library, configure transports, integrate with the VIZ blockchain APIs, sign and broadcast transactions, and handle errors. Production best practices, performance tips, and troubleshooting guidance are included.
|
|
41
|
+
|
|
42
|
+
## Project Structure
|
|
43
|
+
The VIZ JavaScript library exposes a modular API with clear separation of concerns:
|
|
44
|
+
- API client: Provides methods to query blockchain state and subscribe to streams.
|
|
45
|
+
- Authentication: Handles key derivation, WIF conversion, and transaction signing.
|
|
46
|
+
- Broadcasting: Prepares, signs, and broadcasts transactions via configured transport.
|
|
47
|
+
- Formatter: Offers helpers for amounts, permlinks, and account valuation.
|
|
48
|
+
- Utilities: Includes validation, custom protocol helpers, and convenience functions.
|
|
49
|
+
- Transports: HTTP and WebSocket transports for API communication.
|
|
50
|
+
- Config: Centralized configuration for endpoints and chain parameters.
|
|
51
|
+
|
|
52
|
+
```mermaid
|
|
53
|
+
graph TB
|
|
54
|
+
subgraph "Browser"
|
|
55
|
+
EX_HTML["examples/index.html"]
|
|
56
|
+
EX_STREAM["examples/stream.html"]
|
|
57
|
+
EX_BROADCAST["examples/broadcast.html"]
|
|
58
|
+
end
|
|
59
|
+
subgraph "Node.js"
|
|
60
|
+
EX_SERVER["examples/server.js"]
|
|
61
|
+
EX_VOTE["examples/test-vote.js"]
|
|
62
|
+
EX_POST["examples/get-post-content.js"]
|
|
63
|
+
end
|
|
64
|
+
LIB_INDEX["src/index.js"]
|
|
65
|
+
API["src/api/index.js"]
|
|
66
|
+
AUTH["src/auth/index.js"]
|
|
67
|
+
BROADCAST["src/broadcast/index.js"]
|
|
68
|
+
FORMATTER["src/formatter.js"]
|
|
69
|
+
UTILS["src/utils.js"]
|
|
70
|
+
CONFIG["src/config.js"]
|
|
71
|
+
TRANS_HTTP["src/api/transports/http.js"]
|
|
72
|
+
TRANS_WS["src/api/transports/ws.js"]
|
|
73
|
+
EX_HTML --> LIB_INDEX
|
|
74
|
+
EX_STREAM --> LIB_INDEX
|
|
75
|
+
EX_BROADCAST --> LIB_INDEX
|
|
76
|
+
EX_SERVER --> LIB_INDEX
|
|
77
|
+
EX_VOTE --> LIB_INDEX
|
|
78
|
+
EX_POST --> LIB_INDEX
|
|
79
|
+
LIB_INDEX --> API
|
|
80
|
+
LIB_INDEX --> AUTH
|
|
81
|
+
LIB_INDEX --> BROADCAST
|
|
82
|
+
LIB_INDEX --> FORMATTER
|
|
83
|
+
LIB_INDEX --> UTILS
|
|
84
|
+
LIB_INDEX --> CONFIG
|
|
85
|
+
API --> TRANS_HTTP
|
|
86
|
+
API --> TRANS_WS
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Diagram sources**
|
|
90
|
+
- [src/index.js](file://src/index.js#L1-L20)
|
|
91
|
+
- [src/api/index.js](file://src/api/index.js#L1-L271)
|
|
92
|
+
- [src/api/transports/index.js](file://src/api/transports/index.js#L1-L8)
|
|
93
|
+
- [src/api/transports/http.js](file://src/api/transports/http.js)
|
|
94
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js)
|
|
95
|
+
- [src/auth/index.js](file://src/auth/index.js#L1-L133)
|
|
96
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L137)
|
|
97
|
+
- [src/formatter.js](file://src/formatter.js#L1-L87)
|
|
98
|
+
- [src/utils.js](file://src/utils.js#L1-L348)
|
|
99
|
+
- [src/config.js](file://src/config.js#L1-L10)
|
|
100
|
+
- [examples/index.html](file://examples/index.html#L1-L23)
|
|
101
|
+
- [examples/stream.html](file://examples/stream.html#L1-L19)
|
|
102
|
+
- [examples/broadcast.html](file://examples/broadcast.html#L1-L108)
|
|
103
|
+
- [examples/server.js](file://examples/server.js#L1-L34)
|
|
104
|
+
- [examples/test-vote.js](file://examples/test-vote.js#L1-L19)
|
|
105
|
+
- [examples/get-post-content.js](file://examples/get-post-content.js#L1-L5)
|
|
106
|
+
|
|
107
|
+
**Section sources**
|
|
108
|
+
- [README.md](file://README.md#L1-L81)
|
|
109
|
+
- [package.json](file://package.json#L1-L84)
|
|
110
|
+
- [src/index.js](file://src/index.js#L1-L20)
|
|
111
|
+
|
|
112
|
+
## Core Components
|
|
113
|
+
- API client: Exposes generated methods from the method catalog and supports streaming operations, blocks, and transactions.
|
|
114
|
+
- Authentication: Derives keys from usernames and passwords, validates WIF, converts to public keys, and signs transactions.
|
|
115
|
+
- Broadcasting: Prepares transactions with chain metadata, signs with private keys, and broadcasts via configured transport.
|
|
116
|
+
- Formatter: Provides helpers for permlink generation, amount formatting, and account value estimation.
|
|
117
|
+
- Utilities: Account name validation, custom protocol helpers (voice*), and AES-based encoding utilities.
|
|
118
|
+
- Transports: HTTP and WebSocket transports selected dynamically based on configuration.
|
|
119
|
+
- Config: Global getter/setter for transport URLs and chain parameters.
|
|
120
|
+
|
|
121
|
+
**Section sources**
|
|
122
|
+
- [src/api/index.js](file://src/api/index.js#L1-L271)
|
|
123
|
+
- [src/api/methods.js](file://src/api/methods.js#L1-L435)
|
|
124
|
+
- [src/auth/index.js](file://src/auth/index.js#L1-L133)
|
|
125
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L137)
|
|
126
|
+
- [src/formatter.js](file://src/formatter.js#L1-L87)
|
|
127
|
+
- [src/utils.js](file://src/utils.js#L1-L348)
|
|
128
|
+
- [src/api/transports/index.js](file://src/api/transports/index.js#L1-L8)
|
|
129
|
+
- [src/config.js](file://src/config.js#L1-L10)
|
|
130
|
+
|
|
131
|
+
## Architecture Overview
|
|
132
|
+
The library composes a singleton API client that dynamically selects an HTTP or WebSocket transport based on configuration. Methods are generated from a method catalog and exposed on the API client. Broadcasting wraps transaction preparation, signing, and broadcasting through the API.
|
|
133
|
+
|
|
134
|
+
```mermaid
|
|
135
|
+
classDiagram
|
|
136
|
+
class VIZ {
|
|
137
|
+
+constructor(options)
|
|
138
|
+
+start()
|
|
139
|
+
+stop()
|
|
140
|
+
+send(api, data, callback)
|
|
141
|
+
+streamOperations(mode, callback)
|
|
142
|
+
+streamTransactions(mode, callback)
|
|
143
|
+
+streamBlock(mode, callback)
|
|
144
|
+
+streamBlockNumber(mode, callback)
|
|
145
|
+
}
|
|
146
|
+
class Broadcaster {
|
|
147
|
+
+send(tx, privKeys, callback)
|
|
148
|
+
+_prepareTransaction(tx)
|
|
149
|
+
+voteWith(...)
|
|
150
|
+
+contentWith(...)
|
|
151
|
+
+customJsonWith(...)
|
|
152
|
+
}
|
|
153
|
+
class Auth {
|
|
154
|
+
+toWif(name, password, role)
|
|
155
|
+
+wifToPublic(wif)
|
|
156
|
+
+signTransaction(trx, keys, debug)
|
|
157
|
+
+generateKeys(name, password, roles)
|
|
158
|
+
}
|
|
159
|
+
class Formatter {
|
|
160
|
+
+contentPermlink(parentAuthor, parentPermlink)
|
|
161
|
+
+amount(amount, asset)
|
|
162
|
+
+estimateAccountValue(account, opts)
|
|
163
|
+
}
|
|
164
|
+
class Utils {
|
|
165
|
+
+camelCase(str)
|
|
166
|
+
+validateAccountName(value)
|
|
167
|
+
+voiceText(...)
|
|
168
|
+
+voiceEncodedText(...)
|
|
169
|
+
+voicePublication(...)
|
|
170
|
+
}
|
|
171
|
+
VIZ --> "uses" Formatter : "format helpers"
|
|
172
|
+
Broadcaster --> Auth : "signing"
|
|
173
|
+
Broadcaster --> VIZ : "broadcast API"
|
|
174
|
+
Utils --> Formatter : "uses"
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Diagram sources**
|
|
178
|
+
- [src/api/index.js](file://src/api/index.js#L21-L236)
|
|
179
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L16-L137)
|
|
180
|
+
- [src/auth/index.js](file://src/auth/index.js#L13-L133)
|
|
181
|
+
- [src/formatter.js](file://src/formatter.js#L4-L87)
|
|
182
|
+
- [src/utils.js](file://src/utils.js#L3-L47)
|
|
183
|
+
|
|
184
|
+
## Detailed Component Analysis
|
|
185
|
+
|
|
186
|
+
### Browser Setup and Basic Queries
|
|
187
|
+
- Load the built library from the distribution folder.
|
|
188
|
+
- Configure the WebSocket endpoint via configuration.
|
|
189
|
+
- Call API methods to fetch configuration, accounts, and counts.
|
|
190
|
+
|
|
191
|
+
```mermaid
|
|
192
|
+
sequenceDiagram
|
|
193
|
+
participant HTML as "examples/index.html"
|
|
194
|
+
participant VIZ as "viz (src/index.js)"
|
|
195
|
+
participant API as "API (src/api/index.js)"
|
|
196
|
+
participant CFG as "Config (src/config.js)"
|
|
197
|
+
HTML->>CFG : set("websocket", url)
|
|
198
|
+
HTML->>API : getConfig(callback)
|
|
199
|
+
API-->>HTML : {config}
|
|
200
|
+
HTML->>API : getAccounts(names, callback)
|
|
201
|
+
API-->>HTML : [{account}]
|
|
202
|
+
HTML->>API : getAccountCount(callback)
|
|
203
|
+
API-->>HTML : {count}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Diagram sources**
|
|
207
|
+
- [examples/index.html](file://examples/index.html#L9-L20)
|
|
208
|
+
- [src/index.js](file://src/index.js#L1-L20)
|
|
209
|
+
- [src/api/index.js](file://src/api/index.js#L52-L62)
|
|
210
|
+
- [src/config.js](file://src/config.js#L5-L8)
|
|
211
|
+
|
|
212
|
+
**Section sources**
|
|
213
|
+
- [examples/index.html](file://examples/index.html#L1-L23)
|
|
214
|
+
- [README.md](file://README.md#L16-L25)
|
|
215
|
+
|
|
216
|
+
### Real-Time Streaming in the Browser
|
|
217
|
+
- Use the streaming API to receive live operations.
|
|
218
|
+
- The API internally manages transport selection and event emission.
|
|
219
|
+
|
|
220
|
+
```mermaid
|
|
221
|
+
sequenceDiagram
|
|
222
|
+
participant HTML as "examples/stream.html"
|
|
223
|
+
participant API as "API (src/api/index.js)"
|
|
224
|
+
participant WS as "WebSocket Transport"
|
|
225
|
+
HTML->>API : streamOperations(handler)
|
|
226
|
+
API->>WS : connect
|
|
227
|
+
WS-->>API : message(op)
|
|
228
|
+
API-->>HTML : handler(err, op)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Diagram sources**
|
|
232
|
+
- [examples/stream.html](file://examples/stream.html#L10-L15)
|
|
233
|
+
- [src/api/index.js](file://src/api/index.js#L216-L235)
|
|
234
|
+
- [src/api/transports/ws.js](file://src/api/transports/ws.js)
|
|
235
|
+
|
|
236
|
+
**Section sources**
|
|
237
|
+
- [examples/stream.html](file://examples/stream.html#L1-L19)
|
|
238
|
+
- [src/api/index.js](file://src/api/index.js#L121-L191)
|
|
239
|
+
|
|
240
|
+
### Voting Operations (Node.js)
|
|
241
|
+
- Derive a posting key from username and password.
|
|
242
|
+
- Broadcast a vote operation with the derived key.
|
|
243
|
+
|
|
244
|
+
```mermaid
|
|
245
|
+
sequenceDiagram
|
|
246
|
+
participant JS as "examples/test-vote.js"
|
|
247
|
+
participant AUTH as "Auth (src/auth/index.js)"
|
|
248
|
+
participant BROAD as "Broadcaster (src/broadcast/index.js)"
|
|
249
|
+
participant API as "API (src/api/index.js)"
|
|
250
|
+
JS->>AUTH : toWif(username, password, "posting")
|
|
251
|
+
AUTH-->>JS : wif
|
|
252
|
+
JS->>BROAD : upvote(wif, voter, author, permlink, weight, callback)
|
|
253
|
+
BROAD->>BROAD : _prepareTransaction(tx)
|
|
254
|
+
BROAD->>AUTH : signTransaction(trx, keys)
|
|
255
|
+
AUTH-->>BROAD : signedTrx
|
|
256
|
+
BROAD->>API : broadcastTransactionWithCallbackAsync(...)
|
|
257
|
+
API-->>BROAD : result
|
|
258
|
+
BROAD-->>JS : callback(err, result)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Diagram sources**
|
|
262
|
+
- [examples/test-vote.js](file://examples/test-vote.js#L1-L19)
|
|
263
|
+
- [src/auth/index.js](file://src/auth/index.js#L81-L101)
|
|
264
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L24-L47)
|
|
265
|
+
- [src/api/index.js](file://src/api/index.js#L34-L42)
|
|
266
|
+
|
|
267
|
+
**Section sources**
|
|
268
|
+
- [examples/test-vote.js](file://examples/test-vote.js#L1-L19)
|
|
269
|
+
- [README.md](file://README.md#L55-L64)
|
|
270
|
+
|
|
271
|
+
### Content Creation and Broadcasting (Browser)
|
|
272
|
+
- Demonstrate broadcasting a vote, a comment (content), a post, and follow/unfollow via custom_json.
|
|
273
|
+
|
|
274
|
+
```mermaid
|
|
275
|
+
sequenceDiagram
|
|
276
|
+
participant HTML as "examples/broadcast.html"
|
|
277
|
+
participant BROAD as "Broadcaster (src/broadcast/index.js)"
|
|
278
|
+
participant API as "API (src/api/index.js)"
|
|
279
|
+
HTML->>BROAD : vote(wif, voter, author, permlink, weight, callback)
|
|
280
|
+
HTML->>BROAD : content(wif, parent_author, parent_permlink, author, permlink, title, body, metadata, callback)
|
|
281
|
+
HTML->>BROAD : content(wif, "", main_tag, author, permlink, title, body, metadata, callback)
|
|
282
|
+
HTML->>BROAD : customJson(wif, required_auths, required_posting_auths, id, json, callback)
|
|
283
|
+
BROAD->>API : broadcastTransactionWithCallbackAsync(...)
|
|
284
|
+
API-->>BROAD : result
|
|
285
|
+
BROAD-->>HTML : callback(err, result)
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**Diagram sources**
|
|
289
|
+
- [examples/broadcast.html](file://examples/broadcast.html#L15-L103)
|
|
290
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L97-L129)
|
|
291
|
+
- [src/api/index.js](file://src/api/index.js#L40-L46)
|
|
292
|
+
|
|
293
|
+
**Section sources**
|
|
294
|
+
- [examples/broadcast.html](file://examples/broadcast.html#L1-L108)
|
|
295
|
+
|
|
296
|
+
### Node.js Server Usage
|
|
297
|
+
- Use the library in a Node.js script to query account data, state, followers, following, and stream operations.
|
|
298
|
+
|
|
299
|
+
```mermaid
|
|
300
|
+
sequenceDiagram
|
|
301
|
+
participant SERVER as "examples/server.js"
|
|
302
|
+
participant API as "API (src/api/index.js)"
|
|
303
|
+
SERVER->>API : getAccountCount(callback)
|
|
304
|
+
API-->>SERVER : count
|
|
305
|
+
SERVER->>API : getAccounts([name], callback)
|
|
306
|
+
API-->>SERVER : accounts
|
|
307
|
+
SERVER->>API : getState(path, callback)
|
|
308
|
+
API-->>SERVER : state
|
|
309
|
+
SERVER->>API : getFollowing(follower, 0, type, limit, callback)
|
|
310
|
+
API-->>SERVER : following
|
|
311
|
+
SERVER->>API : getFollowers(following, 0, type, limit, callback)
|
|
312
|
+
API-->>SERVER : followers
|
|
313
|
+
SERVER->>API : streamOperations(handler)
|
|
314
|
+
API-->>SERVER : handler(err, op)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
**Diagram sources**
|
|
318
|
+
- [examples/server.js](file://examples/server.js#L3-L33)
|
|
319
|
+
- [src/api/index.js](file://src/api/index.js#L216-L235)
|
|
320
|
+
|
|
321
|
+
**Section sources**
|
|
322
|
+
- [examples/server.js](file://examples/server.js#L1-L34)
|
|
323
|
+
|
|
324
|
+
### Getting Post Content (Node.js)
|
|
325
|
+
- Fetch a single post’s content using an async method.
|
|
326
|
+
|
|
327
|
+
```mermaid
|
|
328
|
+
flowchart TD
|
|
329
|
+
Start(["Start"]) --> Require["Require library"]
|
|
330
|
+
Require --> Call["Call getContentAsync(author, permlink)"]
|
|
331
|
+
Call --> Then["Handle result promise"]
|
|
332
|
+
Then --> Log["Log result"]
|
|
333
|
+
Log --> End(["End"])
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**Diagram sources**
|
|
337
|
+
- [examples/get-post-content.js](file://examples/get-post-content.js#L1-L5)
|
|
338
|
+
|
|
339
|
+
**Section sources**
|
|
340
|
+
- [examples/get-post-content.js](file://examples/get-post-content.js#L1-L5)
|
|
341
|
+
|
|
342
|
+
### Authentication and Transaction Signing
|
|
343
|
+
- Convert credentials to WIF, derive public keys, and sign transactions with chain-specific signing.
|
|
344
|
+
|
|
345
|
+
```mermaid
|
|
346
|
+
flowchart TD
|
|
347
|
+
A["Username + Password + Role"] --> B["Derive Seed"]
|
|
348
|
+
B --> C["Hash Seed -> Private Scalar"]
|
|
349
|
+
C --> D["Multiply by Generator -> Public Point"]
|
|
350
|
+
D --> E["Encode Public Key"]
|
|
351
|
+
E --> F["WIF Encoding"]
|
|
352
|
+
F --> G["Use WIF for Signing"]
|
|
353
|
+
G --> H["Sign Buffer with Chain ID"]
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Diagram sources**
|
|
357
|
+
- [src/auth/index.js](file://src/auth/index.js#L34-L101)
|
|
358
|
+
|
|
359
|
+
**Section sources**
|
|
360
|
+
- [src/auth/index.js](file://src/auth/index.js#L1-L133)
|
|
361
|
+
|
|
362
|
+
### Formatting Helpers
|
|
363
|
+
- Generate permlinks, format amounts, and estimate account value.
|
|
364
|
+
|
|
365
|
+
```mermaid
|
|
366
|
+
flowchart TD
|
|
367
|
+
Start(["Start"]) --> Permlink["contentPermlink(parentAuthor, parentPermlink)"]
|
|
368
|
+
Permlink --> Amount["amount(value, asset)"]
|
|
369
|
+
Amount --> Estimate["estimateAccountValue(account, {gprops, vestingViz})"]
|
|
370
|
+
Estimate --> End(["End"])
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
**Diagram sources**
|
|
374
|
+
- [src/formatter.js](file://src/formatter.js#L69-L84)
|
|
375
|
+
|
|
376
|
+
**Section sources**
|
|
377
|
+
- [src/formatter.js](file://src/formatter.js#L1-L87)
|
|
378
|
+
|
|
379
|
+
### Utilities and Validation
|
|
380
|
+
- Validate account names, and use voice* helpers for custom protocols.
|
|
381
|
+
|
|
382
|
+
```mermaid
|
|
383
|
+
flowchart TD
|
|
384
|
+
Start(["Start"]) --> Validate["validateAccountName(value)"]
|
|
385
|
+
Validate --> VoiceText["voiceText(...)"]
|
|
386
|
+
Validate --> VoiceEnc["voiceEncodedText(...)"]
|
|
387
|
+
Validate --> VoicePub["voicePublication(...)"]
|
|
388
|
+
Validate --> VoiceEncPub["voiceEncodedPublication(...)"]
|
|
389
|
+
VoiceText --> End(["End"])
|
|
390
|
+
VoiceEnc --> End
|
|
391
|
+
VoicePub --> End
|
|
392
|
+
VoiceEncPub --> End
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**Diagram sources**
|
|
396
|
+
- [src/utils.js](file://src/utils.js#L10-L47)
|
|
397
|
+
- [src/utils.js](file://src/utils.js#L84-L206)
|
|
398
|
+
- [src/utils.js](file://src/utils.js#L208-L348)
|
|
399
|
+
|
|
400
|
+
**Section sources**
|
|
401
|
+
- [src/utils.js](file://src/utils.js#L1-L348)
|
|
402
|
+
|
|
403
|
+
## Dependency Analysis
|
|
404
|
+
The library exports a central index that aggregates API, auth, broadcast, formatter, memo, AES, config, and utils. The API client depends on transports and configuration. Broadcasting depends on auth and API for signing and broadcasting.
|
|
405
|
+
|
|
406
|
+
```mermaid
|
|
407
|
+
graph LR
|
|
408
|
+
IDX["src/index.js"] --> API["src/api/index.js"]
|
|
409
|
+
IDX --> AUTH["src/auth/index.js"]
|
|
410
|
+
IDX --> BROAD["src/broadcast/index.js"]
|
|
411
|
+
IDX --> FMTR["src/formatter.js"]
|
|
412
|
+
IDX --> UTL["src/utils.js"]
|
|
413
|
+
IDX --> CFG["src/config.js"]
|
|
414
|
+
API --> TRIDX["src/api/transports/index.js"]
|
|
415
|
+
API --> CFG
|
|
416
|
+
BROAD --> AUTH
|
|
417
|
+
BROAD --> API
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**Diagram sources**
|
|
421
|
+
- [src/index.js](file://src/index.js#L1-L20)
|
|
422
|
+
- [src/api/index.js](file://src/api/index.js#L1-L271)
|
|
423
|
+
- [src/api/transports/index.js](file://src/api/transports/index.js#L1-L8)
|
|
424
|
+
- [src/auth/index.js](file://src/auth/index.js#L1-L133)
|
|
425
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L137)
|
|
426
|
+
- [src/formatter.js](file://src/formatter.js#L1-L87)
|
|
427
|
+
- [src/utils.js](file://src/utils.js#L1-L348)
|
|
428
|
+
- [src/config.js](file://src/config.js#L1-L10)
|
|
429
|
+
|
|
430
|
+
**Section sources**
|
|
431
|
+
- [src/index.js](file://src/index.js#L1-L20)
|
|
432
|
+
- [src/api/index.js](file://src/api/index.js#L1-L271)
|
|
433
|
+
- [src/api/transports/index.js](file://src/api/transports/index.js#L1-L8)
|
|
434
|
+
- [src/auth/index.js](file://src/auth/index.js#L1-L133)
|
|
435
|
+
- [src/broadcast/index.js](file://src/broadcast/index.js#L1-L137)
|
|
436
|
+
- [src/formatter.js](file://src/formatter.js#L1-L87)
|
|
437
|
+
- [src/utils.js](file://src/utils.js#L1-L348)
|
|
438
|
+
- [src/config.js](file://src/config.js#L1-L10)
|
|
439
|
+
|
|
440
|
+
## Performance Considerations
|
|
441
|
+
- Prefer WebSocket transport for real-time streaming to reduce latency and overhead compared to polling.
|
|
442
|
+
- Batch requests where possible and avoid frequent repeated queries for the same data.
|
|
443
|
+
- Use streaming APIs (blocks, transactions, operations) to react to updates efficiently.
|
|
444
|
+
- Cache frequently accessed configuration and chain properties locally to minimize round trips.
|
|
445
|
+
- Minimize transaction signing overhead by preparing transactions off-band and signing only once.
|
|
446
|
+
- Monitor performance metrics emitted by the API client to identify slow endpoints or methods.
|
|
447
|
+
|
|
448
|
+
[No sources needed since this section provides general guidance]
|
|
449
|
+
|
|
450
|
+
## Troubleshooting Guide
|
|
451
|
+
- Unknown transport URL: Ensure the configured URL matches ws/wss or http/https; otherwise, an error is thrown during transport selection.
|
|
452
|
+
- Authentication failures: Verify the derived WIF is valid and corresponds to the account’s posting authority.
|
|
453
|
+
- Broadcasting errors: Inspect the error payload attached to the thrown error object for detailed information.
|
|
454
|
+
- Network connectivity: Confirm the configured endpoint is reachable and supports the chosen transport.
|
|
455
|
+
- Rate limiting: Reduce request frequency and leverage streaming for continuous updates.
|
|
456
|
+
|
|
457
|
+
**Section sources**
|
|
458
|
+
- [src/api/index.js](file://src/api/index.js#L34-L42)
|
|
459
|
+
- [src/api/index.js](file://src/api/index.js#L77-L96)
|
|
460
|
+
- [README.md](file://README.md#L47-L53)
|
|
461
|
+
|
|
462
|
+
## Conclusion
|
|
463
|
+
This guide demonstrated how to use the VIZ JavaScript library for browser and Node.js environments. You learned how to configure transports, query blockchain data, stream live operations, and broadcast transactions securely. By following the examples and best practices outlined here, you can build robust applications that interact with the VIZ blockchain effectively.
|
|
464
|
+
|
|
465
|
+
[No sources needed since this section summarizes without analyzing specific files]
|
|
466
|
+
|
|
467
|
+
## Appendices
|
|
468
|
+
|
|
469
|
+
### Quick Setup Checklist
|
|
470
|
+
- Install the library via npm.
|
|
471
|
+
- Choose a transport URL (WebSocket or HTTP) and set it in configuration.
|
|
472
|
+
- For Node.js, load the library from the built distribution or lib folder.
|
|
473
|
+
- For browsers, include the built script from the distribution folder.
|
|
474
|
+
|
|
475
|
+
**Section sources**
|
|
476
|
+
- [README.md](file://README.md#L11-L14)
|
|
477
|
+
- [README.md](file://README.md#L47-L53)
|
|
478
|
+
- [package.json](file://package.json#L9-L11)
|
|
479
|
+
|
|
480
|
+
### API Method Catalog Reference
|
|
481
|
+
- The API client generates methods from a centralized catalog. Each entry defines the API namespace, method name, and parameter names. Use the generated methods on the API client to call the blockchain.
|
|
482
|
+
|
|
483
|
+
**Section sources**
|
|
484
|
+
- [src/api/methods.js](file://src/api/methods.js#L1-L435)
|
|
485
|
+
- [src/api/index.js](file://src/api/index.js#L238-L262)
|