Skip to content

Commit 63ac85e

Browse files
committed
fix up minor inconsistencies, add python to quickstart
1 parent e104e5b commit 63ac85e

File tree

7 files changed

+92
-124
lines changed

7 files changed

+92
-124
lines changed

docusaurus.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ const config = {
150150
darkTheme: darkCodeTheme,
151151
additionalLanguages: [
152152
"rust",
153-
"swift",
154-
"kotlin"
153+
"python",
154+
"kotlin",
155+
"swift"
155156
]
156157
},
157158
}),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
"doc-snippets": {
7474
"extract": {
75-
"include": "./**/*.{ts,tsx,js,json,yaml,txt,md,graphql,cue,kt,kts}",
75+
"include": "./**/*.{ts,tsx,js,json,yaml,txt,md,graphql,cue,kt,kts,py}",
7676
"ignore": [
7777
"./**/node_modules/**",
7878
"./**/.polywrap/**",

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const sidebars = {
2020
label: 'Quick Start',
2121
items: [
2222
'quick-start/javascript',
23+
'quick-start/python',
2324
'quick-start/kotlin',
2425
'quick-start/swift',
2526
]

snippets/quick-start/py/program.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# $start: quickstart-py-import-init-client
2+
from polywrap import (
3+
Uri, # Required to construct a valid wrap URI
4+
PolywrapClient, # The client itself
5+
PolywrapClientConfigBuilder,
6+
sys_bundle,
7+
web3_bundle,
8+
)
9+
10+
builder = PolywrapClientConfigBuilder().add_bundle(sys_bundle).add_bundle(web3_bundle)
11+
12+
config = builder.build()
13+
14+
client = PolywrapClient(config)
15+
# $end
16+
17+
# $start: quickstart-py-invoke-client
18+
result = client.invoke(
19+
uri=Uri.from_str("wrapscan.io/polywrap/sha3@1"),
20+
method="sha3_256",
21+
args={
22+
"message": "Hello Polywrap!",
23+
},
24+
encode_result=False,
25+
)
26+
27+
print(result)
28+
# $end
29+
30+
# $start: quickstart-py-uniswap
31+
wethResult = client.invoke(
32+
uri=Uri.from_str("wrapscan.io/polywrap/uniswap-v3@1"),
33+
method="fetchToken",
34+
args={
35+
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
36+
"chainId": "MAINNET",
37+
},
38+
encode_result=False,
39+
)
40+
41+
print(wethResult)
42+
43+
usdcResult = client.invoke(
44+
uri=Uri.from_str("wrapscan.io/polywrap/uniswap-v3@1"),
45+
method="fetchToken",
46+
args={
47+
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
48+
"chainId": "MAINNET",
49+
},
50+
encode_result=False,
51+
)
52+
53+
print(usdcResult)
54+
55+
poolAddressResult = client.invoke(
56+
uri=Uri.from_str("wrapscan.io/polywrap/uniswap-v3@1"),
57+
method="getPoolAddress",
58+
args={
59+
"tokenA": wethResult,
60+
"tokenB": usdcResult,
61+
"fee": "MEDIUM",
62+
},
63+
encode_result=False,
64+
)
65+
66+
print(poolAddressResult)
67+
# $end

src/docs/quick-start/javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ At the top of your `index.js` file, import the `PolywrapClient` and instantiate
6464
$snippet: quickstart-js-init-client
6565
```
6666

67-
At this point, you can already invoke Wraps! In the simple example below, we will invoke the Logger Wrap within our `main` function:
67+
At this point, you can already invoke Wraps! In the simple example below, we will invoke the SHA3 Wrap within our `main` function:
6868

6969
```javascript
7070
$snippet: quickstart-js-1st-invoke

src/docs/quick-start/kotlin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ You can now instantiate the Polywrap Client with a default configuration within
5151
$snippet: quickstart-kt-init-client
5252
```
5353

54-
At this point, you can already invoke Wraps! In the simple example below, we will invoke the Logger Wrap within our `main` function:
54+
At this point, you can already invoke Wraps! In the simple example below, we will invoke the SHA3 Wrap within our `main` function:
5555

5656
```kotlin title="App.kt"
5757
$snippet: quickstart-kt-invoke-client

src/docs/quick-start/python.md

Lines changed: 18 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -9,87 +9,38 @@ To use [Wraps](/concepts/wraps) in your app, all you need is the [Polywrap Clien
99

1010
### NodeJS application boilerplate
1111

12-
We'll be using a simple NodeJS application boilerplate for this guide.
13-
14-
Using `npm init` or `yarn init` within a directory initialize an empty NodeJS project.
15-
16-
Within `package.json`, change the `type` of the project to `"module"`. This is not required as you can also use `require`.
17-
18-
```json title="package.json"
19-
{
20-
"name": "my-app-name",
21-
//...
22-
"type": "module",
23-
//...
24-
}
25-
```
26-
27-
Add an `index.js` file with the following code:
28-
29-
```javascript title="index.js"
30-
async function main() {
31-
// your code goes here...
32-
}
33-
34-
main()
35-
.then(() => {
36-
process.exit(0);
37-
})
38-
.catch((error) => {
39-
console.error(error);
40-
process.exit(1);
41-
});
42-
43-
```
12+
We'll be using a simple empty python file named `program.py` as our boilerplate.
4413

4514
### Install the Polywrap Client
4615

47-
Using `NPM`:
48-
```
49-
npm install --save @polywrap/client-js
50-
```
51-
52-
Using `yarn`:
16+
You can install the Polywrap client using `pip`:
5317
```
54-
yarn add @polywrap/client-js
18+
pip install polywrap
5519
```
5620

5721
### Invoking your first Wrap
5822

5923
In order to invoke a Wrap, we first need to instantiate the Polywrap Client:
6024

61-
At the top of your `index.js` file, import the `PolywrapClient` and instantiate it:
25+
At the top of your `program.py` file, import the `PolywrapClient` and instantiate it:
6226

63-
```javascript title="index.js"
64-
import { PolywrapClient } from "@polywrap/client-js";
65-
66-
const client = new PolywrapClient();
27+
```python title="program.py"
28+
$snippet: quickstart-py-import-init-client
6729
```
6830

69-
At this point, you can already invoke Wraps! In the simple example below, we will invoke the Logger Wrap within our `main` function:
70-
71-
```javascript
72-
const result = await client.invoke({
73-
uri: "wrapscan.io/polywrap/sha3@1.0",
74-
method: "sha3_256",
75-
args: {
76-
message: "Hello Polywrap!",
77-
},
78-
});
31+
At this point, you can already invoke Wraps! In the simple example below, we will invoke the SHA3 Wrap:
7932

80-
console.log(result);
33+
```python title="program.py"
34+
$snippet: quickstart-py-invoke-client
8135
```
8236

83-
Running the application using `node index.js`, you should now see the following appear in your console:
37+
Running the application using `python program.py`, you should now see the following appear in your console:
8438

8539
```
86-
{
87-
ok: true,
88-
value: 'ba5a5d5fb7674f5975f0ecd0cd9a2f4bcadc9c04f5ac2ab3a887d8f10355fc38'
89-
}
40+
ba5a5d5fb7674f5975f0ecd0cd9a2f4bcadc9c04f5ac2ab3a887d8f10355fc38
9041
```
9142

92-
Here we can see the structure of the `InvokeResult` object. It's `ok` field denotes whether the Wrap's invocation was successful, and the `value` is the return value of the invocation.
43+
This is the return value of our invocation.
9344

9445
#### What's going on here?
9546

@@ -99,14 +50,12 @@ Under the hood, through a process we call URI Resolution, the Polywrap Client kn
9950

10051
The `PolywrapClient` comes pre-configured with everything you need for most Web2 and Web3 use-cases by default.
10152

102-
#### The `InvokeResult` object
103-
104-
The `InvokeResult` object can have one of two structures:
53+
#### Invocation return value
10554

106-
- A successful Wrap invocation returns `{ ok: true, value: ... }` with `value` being the return value of the Wrap invocation. This can be anything - a boolean value, a string, an object, etc.
107-
- A failed Wrap invocation returns `{ ok: false, error: ... }` with `error` describing the reason for invocation failure.
55+
Invoking a wrap can result in one of two scenarios:
10856

109-
Although not particularly useful in our last example, our next example leverages the fact that Wrap invocations return a value.
57+
- A successful Wrap invocation returns the return value of the Wrap invocation. This can be anything - a boolean value, a string, an object, etc.
58+
- A failed Wrap invocation throws an exception describing the reason for invocation failure.
11059

11160
### Universal SDKs
11261

@@ -120,58 +69,8 @@ Now we'll invoke the Uniswap V3 Wrap which is a port of the Uniswap SDK, but wri
12069

12170
We can use the Uniswap Wrap to fetch Uniswap's basic data related to the WETH and USDC tokes, find the address of the pool for those two tokens. We are also checking each result for errors.
12271

123-
```javascript
124-
const wethResult = await client.invoke({
125-
uri: "wrapscan.io/polywrap/uniswap-v3@1.0",
126-
method: "fetchToken",
127-
args: {
128-
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
129-
chainId: "MAINNET",
130-
},
131-
});
132-
133-
// Log the invocation error and stop execution if the invocation fails
134-
if(!wethResult.ok) {
135-
console.log(wethResult.error)
136-
return;
137-
}
138-
139-
console.log("WETH:", wethResult.value);
140-
141-
const usdcResult = await client.invoke({
142-
uri: "wrapscan.io/polywrap/uniswap-v3@1.0",
143-
method: "fetchToken",
144-
args: {
145-
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
146-
chainId: "MAINNET",
147-
},
148-
});
149-
150-
// Log the invocation error and stop execution if the invocation fails
151-
if(!usdcResult.ok) {
152-
console.log(usdcResult.error)
153-
return;
154-
}
155-
156-
console.log("USDC:", usdcResult.value);
157-
158-
const poolAddressResult = await client.invoke({
159-
uri: "wrapscan.io/polywrap/uniswap-v3@1.0",
160-
method: "getPoolAddress",
161-
args: {
162-
tokenA: wethResult.value,
163-
tokenB: usdcResult.value,
164-
fee: "MEDIUM"
165-
},
166-
});
167-
168-
// Log the invocation error and stop execution if the invocation fails
169-
if(!poolAddressResult.ok) {
170-
console.log(poolAddressResult.error);
171-
return;
172-
}
173-
174-
console.log("Pool address:", poolAddressResult.value);
72+
```python title="program.py"
73+
$snippet: quickstart-py-uniswap
17574
```
17675

17776
You can see more examples on how to use the Uniswap V3 Wrap in its [docs page](https://uniswap.docs.wrappers.io/).

0 commit comments

Comments
 (0)