@@ -5,16 +5,53 @@ A TypeScript SDK for interacting with PolkaVM Query (PVQ)
5
5
## Installation
6
6
7
7
``` bash
8
+ # Install the published package
9
+ npm install @open-web3/pvq
10
+ # or
11
+ yarn add @open-web3/pvq
12
+ # or
13
+ pnpm add @open-web3/pvq
14
+
15
+ # Or install from source
8
16
pnpm add pvq-sdk
9
17
```
10
18
19
+ ## Quick Start
20
+
21
+ ``` typescript
22
+ import { ApiPromise } from ' @polkadot/api' ;
23
+ import { PvqProgram } from ' @open-web3/pvq' ;
24
+
25
+ // Connect to a Polkadot node
26
+ const api = await ApiPromise .create ({
27
+ provider: ' ws://localhost:9944'
28
+ });
29
+
30
+ // Create PVQ program instance
31
+ const program = new PvqProgram (
32
+ api ,
33
+ guestProgramBytes , // Uint8Array or hex string
34
+ programMetadata // Program metadata object
35
+ );
36
+
37
+ // Execute a query
38
+ const result = await program .entrypoint .sumBalance ([
39
+ 21 ,
40
+ [' 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5' ]
41
+ ], {
42
+ gasLimit: 1000000000000000000n
43
+ });
44
+
45
+ console .log (' Query result:' , result );
46
+ ```
47
+
11
48
## Usage Examples
12
49
13
50
### Basic Program Execution
14
51
15
52
``` typescript
16
53
import { ApiPromise , WsProvider } from ' @polkadot/api' ;
17
- import { PvqProgram } from ' pvq-sdk ' ;
54
+ import { PvqProgram } from ' @open-web3/pvq ' ;
18
55
19
56
async function executeProgram() {
20
57
const provider = new WsProvider (' ws://127.0.0.1:8000' );
@@ -60,7 +97,7 @@ const result = await program.executeQuery('sum_balance', { gasLimit: 1000000n },
60
97
61
98
``` typescript
62
99
// Fetch metadata from the chain
63
- const metadata = await program .metadata ();
100
+ const metadata = await program .getMetadata ();
64
101
console .log (' Chain metadata:' , metadata );
65
102
```
66
103
@@ -75,6 +112,33 @@ console.log('Extensions matched:', matched); // true or throws error if not matc
75
112
console .log (' Cached result:' , program .extensionsMatched ); // true/false/undefined
76
113
```
77
114
115
+ ## API Reference
116
+
117
+ ### PvqProgram
118
+
119
+ Main class for interacting with PVQ programs.
120
+
121
+ #### Constructor
122
+
123
+ ``` typescript
124
+ new PvqProgram (
125
+ api : ApiBase < ApiTypes > ,
126
+ guestProgram : Uint8Array | ` 0x${string } ` ,
127
+ programMetadata : Record < string , unknown >
128
+ )
129
+ ```
130
+
131
+ #### Methods
132
+
133
+ - ` executeQuery(entrypoint, options, params) ` - Execute a query on the program
134
+ - ` checkExtensions() ` - Check if required extensions are available
135
+ - ` getMetadata() ` - Get runtime metadata
136
+
137
+ #### Properties
138
+
139
+ - ` entrypoint ` - Object containing all available entrypoints as camelCase methods
140
+ - ` extensionsMatched ` - Boolean indicating if extensions check passed
141
+
78
142
## Program Metadata Format
79
143
80
144
Your program metadata should follow this structure:
0 commit comments